Skip to content

Commit 00ee1ef

Browse files
authored
refactor: Salesforce - account query based on website (#19799)
* Refactor account lookup to include website prefixes * Type fix
1 parent 6cdc9c9 commit 00ee1ef

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/app-store/salesforce/lib/CrmService.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -890,11 +890,13 @@ export default class SalesforceCRMService implements CRM {
890890
log.info("getAccountIdBasedOnEmailDomainOfContacts", safeStringify({ email, emailDomain }));
891891
// First check if an account has the same website as the email domain of the attendee
892892
const accountQuery = await conn.query(
893-
`SELECT Id, Website FROM Account WHERE Website LIKE '%${emailDomain}%' LIMIT 1`
893+
`SELECT Id, Website FROM Account WHERE Website IN ('${emailDomain}', 'www.${emailDomain}',
894+
'http://www.${emailDomain}', 'http://${emailDomain}',
895+
'https://www.${emailDomain}', 'https://${emailDomain}') LIMIT 1`
894896
);
895-
896897
if (accountQuery.records.length > 0) {
897898
const account = accountQuery.records[0] as { Id: string };
899+
log.info("Found account based on email domain", safeStringify({ accountId: account.Id }));
898900
return account.Id;
899901
}
900902

@@ -903,7 +905,15 @@ export default class SalesforceCRMService implements CRM {
903905
`SELECT Id, Email, AccountId FROM Contact WHERE Email LIKE '%@${emailDomain}' AND AccountId != null`
904906
);
905907

906-
return this.getDominantAccountId(response.records as { AccountId: string }[]);
908+
const accountId = this.getDominantAccountId(response.records as { AccountId: string }[]);
909+
910+
if (accountId) {
911+
log.info("Found account based on other contacts", safeStringify({ accountId }));
912+
} else {
913+
log.info("No account found");
914+
}
915+
916+
return accountId;
907917
}
908918

909919
private async getAccountBasedOnEmailDomainOfContacts(email: string) {

0 commit comments

Comments
 (0)