@@ -883,20 +883,34 @@ export default class SalesforceCRMService implements CRM {
883
883
} ) ;
884
884
}
885
885
886
+ public getAllPossibleAccountWebsiteFromEmailDomain ( emailDomain : string ) {
887
+ return [
888
+ emailDomain ,
889
+ `www.${ emailDomain } ` ,
890
+ `http://www.${ emailDomain } ` ,
891
+ `http://${ emailDomain } ` ,
892
+ `https://www.${ emailDomain } ` ,
893
+ `https://${ emailDomain } ` ,
894
+ ] . join ( ", " ) ;
895
+ }
896
+
886
897
private async getAccountIdBasedOnEmailDomainOfContacts ( email : string ) {
887
898
const conn = await this . conn ;
888
899
const emailDomain = email . split ( "@" ) [ 1 ] ;
889
900
const log = logger . getSubLogger ( { prefix : [ `[getAccountIdBasedOnEmailDomainOfContacts]:${ email } ` ] } ) ;
890
901
log . info ( "getAccountIdBasedOnEmailDomainOfContacts" , safeStringify ( { email, emailDomain } ) ) ;
891
902
// First check if an account has the same website as the email domain of the attendee
892
903
const accountQuery = await conn . query (
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`
904
+ `SELECT Id, Website FROM Account WHERE Website IN (${ this . getAllPossibleAccountWebsiteFromEmailDomain (
905
+ emailDomain
906
+ ) } ) LIMIT 1`
896
907
) ;
897
908
if ( accountQuery . records . length > 0 ) {
898
- const account = accountQuery . records [ 0 ] as { Id : string } ;
899
- log . info ( "Found account based on email domain" , safeStringify ( { accountId : account . Id } ) ) ;
909
+ const account = accountQuery . records [ 0 ] as { Id : string ; Website : string } ;
910
+ log . info (
911
+ "Found account based on email domain" ,
912
+ safeStringify ( { emailDomain, accountWebsite : account . Website , accountId : account . Id } )
913
+ ) ;
900
914
return account . Id ;
901
915
}
902
916
@@ -923,13 +937,26 @@ export default class SalesforceCRMService implements CRM {
923
937
log . info ( "Querying first account matching email domain" , safeStringify ( { emailDomain } ) ) ;
924
938
// First check if an account has the same website as the email domain of the attendee
925
939
const accountQuery = await conn . query (
926
- `SELECT Id, OwnerId, Owner.Email FROM Account WHERE Website LIKE '%${ emailDomain } %' LIMIT 1`
940
+ `SELECT Id, OwnerId, Owner.Email FROM Account WHERE Website IN (${ this . getAllPossibleAccountWebsiteFromEmailDomain (
941
+ emailDomain
942
+ ) } ) LIMIT 1`
927
943
) ;
928
944
929
945
if ( accountQuery . records . length > 0 ) {
930
- log . info ( "Found account matching email domain" , safeStringify ( { emailDomain } ) ) ;
946
+ const account = accountQuery . records [ 0 ] as {
947
+ Id ?: string ;
948
+ OwnerId ?: string ;
949
+ Owner ?: { Email ?: string } ;
950
+ Website ?: string ;
951
+ } ;
952
+
953
+ log . info (
954
+ "Found account matching email domain" ,
955
+ safeStringify ( { emailDomain, accountWebsite : account . Website , accountId : account . Id } )
956
+ ) ;
957
+
931
958
return {
932
- ...( accountQuery . records [ 0 ] as { Id ?: string ; OwnerId ?: string ; Owner ?: { Email ?: string } } ) ,
959
+ ...account ,
933
960
Email : undefined ,
934
961
} ;
935
962
}
0 commit comments