From 2444598e38743f748dd32c095580015b4acf22ac Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Wed, 4 Dec 2024 02:46:51 -0500 Subject: [PATCH] Fuzzy search account website, fallback to contacts (#17989) Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> --- packages/app-store/salesforce/lib/CrmService.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/app-store/salesforce/lib/CrmService.ts b/packages/app-store/salesforce/lib/CrmService.ts index 6e8c7af64e..b3dc0be464 100644 --- a/packages/app-store/salesforce/lib/CrmService.ts +++ b/packages/app-store/salesforce/lib/CrmService.ts @@ -800,6 +800,17 @@ export default class SalesforceCRMService implements CRM { const conn = await this.conn; const emailDomain = email.split("@")[1]; + // First check if an account has the same website as the email domain of the attendee + const accountQuery = await conn.query( + `SELECT Id, Website FROM Account WHERE Website LIKE '%${emailDomain}%'` + ); + + if (accountQuery.records.length > 0) { + const account = accountQuery.records[0] as { Id: string }; + return account.Id; + } + + // Fallback to querying which account the majority of contacts are under const response = await conn.query( `SELECT Id, Email, AccountId FROM Contact WHERE Email LIKE '%@${emailDomain}' AND AccountId != null` );