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 <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Bailey Pumfleet <[email protected]>
This commit is contained in:
1 file changed
+4
-1
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user