Skip to content

Scheduling infrastructure for absolutely everyone.

refactor: Salesforce - account query based on website (#19799)

Joe Au-Yeung00ee1ef44185
diff --git a/packages/app-store/salesforce/lib/CrmService.ts b/packages/app-store/salesforce/lib/CrmService.ts
index 3f462d4b6a5..db355bcc601 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) {