From 62d162f001e2d985038d2ed9e4c510d28b026eb0 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:27:08 -0400 Subject: [PATCH] fix: Salesforce if contact was created don't create new lead as well (#17299) * fix: salesforce event creation duplicate error * chore: message * If contact was created, don't create a new lead * Add boolean for no accountId * Remove debug artifact --------- Co-authored-by: Udit Takkar Co-authored-by: Alex van Andel Co-authored-by: Bailey Pumfleet --- packages/app-store/salesforce/lib/CrmService.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/app-store/salesforce/lib/CrmService.ts b/packages/app-store/salesforce/lib/CrmService.ts index 2b5a474529..7b78af01b3 100644 --- a/packages/app-store/salesforce/lib/CrmService.ts +++ b/packages/app-store/salesforce/lib/CrmService.ts @@ -406,6 +406,8 @@ export default class SalesforceCRMService implements CRM { const accountId = this.getDominantAccountId(response.records as { AccountId: string }[]); + let contactCreated = false; + if (accountId && appOptions.createNewContactUnderAccount) { // First see if the contact already exists and connect it to the account const userQuery = await conn.query(`SELECT Id, Email FROM Contact WHERE Email = '${attendee.email}'`); @@ -432,11 +434,12 @@ export default class SalesforceCRMService implements CRM { .then((result) => { if (result.success) { createdContacts.push({ id: result.id, email: attendee.email }); + contactCreated = true; } }); } - if (appOptions.createLeadIfAccountNull) { + if (!accountId && appOptions.createLeadIfAccountNull && !contactCreated) { // Check to see if the lead exists already const leadQuery = await conn.query(`SELECT Id, Email FROM Lead WHERE Email = '${attendee.email}'`); if (leadQuery.records.length) {