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 17, 2023
2 parents 28c7236 + 9186b8d commit c14d77b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 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.1",
"version": "2.15.2",
"license": "ISC",
"engines": {
"node": "16.x"
Expand Down
49 changes: 26 additions & 23 deletions src/external-services/salesforce/salesforce.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,31 +1013,34 @@ export class SalesforceService {
leadOrContactId: { leadId?: string; contactId?: string },
infoCoId: string
) {
const campaignMemberId = await this.findCampaignMember(
leadOrContactId,
infoCoId
);
const { leadId, contactId } = leadOrContactId;
if (!campaignMemberId) {
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;
try {
let campaignMemberId = await this.findCampaignMember(
leadOrContactId,
infoCoId
);
const { leadId, contactId } = leadOrContactId;
if (!campaignMemberId) {
campaignMemberId = (await this.createRecord(
ObjectNames.CAMPAIGN_MEMBER,
{
...(leadId
? {
LeadId: leadId,
}
: { ContactId: contactId }),
CampaignId: infoCoId,
Status: 'Inscrit',
}
)) as string;
}
return campaignMemberId;
} 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;
}
}

Expand Down

0 comments on commit c14d77b

Please sign in to comment.