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 <udit222001@gmail.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
Co-authored-by: Bailey Pumfleet <bailey@pumfleet.co.uk>
This commit is contained in:
Joe Au-Yeung
2024-10-24 19:27:08 +00:00
committed by GitHub
co-authored by Udit Takkar Alex van Andel Bailey Pumfleet
parent 8811ebcc33
commit 62d162f001
@@ -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) {