From 00ee1ef44185b763f7a89960222c43ca15459e05 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Fri, 7 Mar 2025 01:23:49 +0900 Subject: [PATCH] refactor: Salesforce - account query based on website (#19799) * Refactor account lookup to include website prefixes * Type fix --- packages/app-store/salesforce/lib/CrmService.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/app-store/salesforce/lib/CrmService.ts b/packages/app-store/salesforce/lib/CrmService.ts index 3f462d4b6a..db355bcc60 100644 --- a/packages/app-store/salesforce/lib/CrmService.ts +++ b/packages/app-store/salesforce/lib/CrmService.ts @@ -890,11 +890,13 @@ export default class SalesforceCRMService implements CRM { log.info("getAccountIdBasedOnEmailDomainOfContacts", safeStringify({ email, emailDomain })); // 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}%' LIMIT 1` + `SELECT Id, Website FROM Account WHERE Website IN ('${emailDomain}', 'www.${emailDomain}', + 'http://www.${emailDomain}', 'http://${emailDomain}', + 'https://www.${emailDomain}', 'https://${emailDomain}') LIMIT 1` ); - if (accountQuery.records.length > 0) { const account = accountQuery.records[0] as { Id: string }; + log.info("Found account based on email domain", safeStringify({ accountId: account.Id })); return account.Id; } @@ -903,7 +905,15 @@ export default class SalesforceCRMService implements CRM { `SELECT Id, Email, AccountId FROM Contact WHERE Email LIKE '%@${emailDomain}' AND AccountId != null` ); - return this.getDominantAccountId(response.records as { AccountId: string }[]); + const accountId = this.getDominantAccountId(response.records as { AccountId: string }[]); + + if (accountId) { + log.info("Found account based on other contacts", safeStringify({ accountId })); + } else { + log.info("No account found"); + } + + return accountId; } private async getAccountBasedOnEmailDomainOfContacts(email: string) {