Skip to content

Commit

Permalink
Merge branch 'hotfix/fix_sf_duplicate_errors'
Browse files Browse the repository at this point in the history
  • Loading branch information
emile-bex committed Oct 16, 2023
2 parents b278d9f + 334d5b5 commit 28c7236
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linkedout-backend",
"version": "2.15.0",
"version": "2.15.1",
"license": "ISC",
"engines": {
"node": "16.x"
Expand Down
35 changes: 22 additions & 13 deletions src/external-services/salesforce/salesforce.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class SalesforceService {
if (
(err as SalesforceError).errorCode === ErrorCodes.DUPLICATES_DETECTED
) {
return (err as SalesforceError).duplicateResut.matchResults[0]
return (err as SalesforceError).duplicateResult.matchResults[0]
.matchRecords[0].record.Id;
}
console.error(err);
Expand Down Expand Up @@ -206,7 +206,7 @@ export class SalesforceService {
if (
(err as SalesforceError).errorCode === ErrorCodes.DUPLICATES_DETECTED
) {
return (err as SalesforceError).duplicateResut.matchResults[0]
return (err as SalesforceError).duplicateResult.matchResults[0]
.matchRecords[0].record.Id;
}
if (
Expand Down Expand Up @@ -280,7 +280,7 @@ export class SalesforceService {
if (
(err as SalesforceError).errorCode === ErrorCodes.DUPLICATES_DETECTED
) {
return (err as SalesforceError).duplicateResut.matchResults[0]
return (err as SalesforceError).duplicateResult.matchResults[0]
.matchRecords[0].record.Id;
}
console.error(err);
Expand Down Expand Up @@ -1019,17 +1019,26 @@ export class SalesforceService {
);
const { leadId, contactId } = leadOrContactId;
if (!campaignMemberId) {
return this.createRecord(ObjectNames.CAMPAIGN_MEMBER, {
...(leadId
? {
LeadId: leadId,
}
: { ContactId: contactId }),
CampaignId: infoCoId,
Status: 'Inscrit',
});
try {
return this.createRecord(ObjectNames.CAMPAIGN_MEMBER, {
...(leadId
? {
LeadId: leadId,
}
: { ContactId: contactId }),
CampaignId: infoCoId,
Status: 'Inscrit',
});
} catch (err) {
// Case where the flow is not as fast as the api call
if ((err as SalesforceError).errorCode === ErrorCodes.DUPLICATE_VALUE) {
return this.findCampaignMember(leadOrContactId, infoCoId);
}
console.error(err);
throw err;
}
return campaignMemberId;
}
return campaignMemberId;
}

async createCandidateLead(
Expand Down
3 changes: 2 additions & 1 deletion src/external-services/salesforce/salesforce.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { AnyCantFix } from 'src/utils/types';

export const ErrorCodes = {
DUPLICATES_DETECTED: 'DUPLICATES_DETECTED',
DUPLICATE_VALUE: 'DUPLICATE_VALUE',
CANNOT_UPDATE_CONVERTED_LEAD: 'CANNOT_UPDATE_CONVERTED_LEAD',
FIELD_INTEGRITY_EXCEPTION: 'FIELD_INTEGRITY_EXCEPTION',
FIELD_FILTER_VALIDATION_EXCEPTION: 'FIELD_FILTER_VALIDATION_EXCEPTION',
Expand All @@ -50,7 +51,7 @@ export type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
export interface SalesforceError {
errorCode: ErrorCode;
message: string;
duplicateResut: {
duplicateResult: {
matchResults: {
matchRecords: {
record: {
Expand Down

0 comments on commit 28c7236

Please sign in to comment.