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

* Refactor account lookup to include website prefixes

* Type fix
This commit is contained in:
Joe Au-Yeung authored and GitHub committed 2025-03-06 21:53:49 +05:30
1 parent 6cdc9c9f59
commit 00ee1ef441
1 file changed
+13 -3
@@ -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) {