fix: Salesforce - if no contact throw Error (#19271)

* Throw error if no contact is passed to createEvent

* chore: update error message

* chore

---------

Co-authored-by: Udit Takkar <udit222001@gmail.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
This commit is contained in:
Joe Au-Yeung
2025-02-13 16:01:46 -05:00
committed by GitHub
co-authored by Udit Takkar Udit Takkar
parent 401209810a
commit 466b3e4c08
@@ -195,15 +195,16 @@ export default class SalesforceCRMService implements CRM {
} else {
log.warn("No organizer email found for event", event?.organizer);
}
log.info(`Organizer found with Salesforce id ${ownerId}`);
/**
* Current code assume that contacts is not empty.
* I'm not going to reject the promise since I don't know if this is a valid assumption.
**/
const [firstContact] = contacts;
if (!firstContact?.id) {
log.warn("No contacts found for event", contacts);
log.error("No contacts found for event", { contacts });
throw new Error("No contacts found for event");
}
const eventWhoIds = contacts.reduce((contactIds, contact) => {
@@ -565,7 +566,7 @@ export default class SalesforceCRMService implements CRM {
const leadQuery = await conn.query(
`SELECT Id, Email FROM Lead WHERE Email = '${attendee.email}' LIMIT 1`
);
if (leadQuery.records.length) {
if (leadQuery.records.length > 0) {
const contact = leadQuery.records[0] as { Id: string; Email: string };
return [{ id: contact.Id, email: contact.Email }];
}
@@ -1229,7 +1230,7 @@ export default class SalesforceCRMService implements CRM {
const userQuery = await conn.query(
`SELECT Id, Email FROM Contact WHERE Email = '${attendee.email}' LIMIT 1`
);
if (userQuery.records.length) {
if (userQuery.records.length > 0) {
const contact = userQuery.records[0] as { Id: string; Email: string };
await conn.sobject(SalesforceRecordEnum.CONTACT).update({
// The first argument is the WHERE clause