From 16e8d483967180886193ec56c416b22058e7f464 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 22 Jan 2026 11:48:48 -0600 Subject: [PATCH] Website: update deliver-contact-form-message (#38640) Changes: - Updated the deliver-contact-form-message action to attempt to create/update CRM records before it sends a contact form email. --- .../deliver-contact-form-message.js | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/website/api/controllers/deliver-contact-form-message.js b/website/api/controllers/deliver-contact-form-message.js index 15bc5708b1..321191056f 100644 --- a/website/api/controllers/deliver-contact-form-message.js +++ b/website/api/controllers/deliver-contact-form-message.js @@ -76,6 +76,42 @@ module.exports = { ); } + let attributionCookieOrUndefined = this.req.cookies.marketingAttribution; + + await sails.helpers.flow.build(async ()=>{ + let recordIds = await sails.helpers.salesforce.updateOrCreateContactAndAccount.with({ + emailAddress: emailAddress, + firstName: firstName, + lastName: lastName, + contactSource: 'Website - Contact forms', + description: `Sent a contact form message: ${message}`, + marketingAttributionCookie: attributionCookieOrUndefined + }).intercept((err)=>{ + return new Error(`Could not create/update a contact or account. Full error: ${require('util').inspect(err)}`); + }); + + // If the Contact record returned by the updateOrCreateContactAndAccount does not have a parent Account record, throw an error to stop the build helper. + if(!recordIds.salesforceAccountId) { + throw new Error(`Could not create historical event. The contact record (ID: ${recordIds.salesforceContactId}) returned by the updateOrCreateContactAndAccount helper is missing a parent account record.`); + } + // Create the new Fleet website page view record. + await sails.helpers.salesforce.createHistoricalEvent.with({ + salesforceAccountId: recordIds.salesforceAccountId, + salesforceContactId: recordIds.salesforceContactId, + eventType: 'Intent signal', + intentSignal: 'Submitted the "Send a message" form', + eventContent: message, + }).intercept((err)=>{ + return new Error(`Could not create an historical event. Full error: ${require('util').inspect(err)}`); + }); + }).tolerate((err)=>{ + if(err) { + sails.log.warn(`When a user submitted a contact form message, a contact/account/historical event could not be created/updated in the CRM for this email address: ${emailAddress}. Full error: ${require('util').inspect(err)}`); + } + return; + }); + + let subject = 'New contact form message'; if(userHasPremiumSubscription) { // If the user has a Fleet Premium subscription, prepend the message with details about their subscription. @@ -108,42 +144,6 @@ Fleet Premium subscription details: message, }, }); - - let attributionCookieOrUndefined = this.req.cookies.marketingAttribution; - - sails.helpers.flow.build(async ()=>{ - let recordIds = await sails.helpers.salesforce.updateOrCreateContactAndAccount.with({ - emailAddress: emailAddress, - firstName: firstName, - lastName: lastName, - contactSource: 'Website - Contact forms', - description: `Sent a contact form message: ${message}`, - marketingAttributionCookie: attributionCookieOrUndefined - }).intercept((err)=>{ - return new Error(`Could not create/update a contact or account. Full error: ${require('util').inspect(err)}`); - }); - - // If the Contact record returned by the updateOrCreateContactAndAccount does not have a parent Account record, throw an error to stop the build helper. - if(!recordIds.salesforceAccountId) { - throw new Error(`Could not create historical event. The contact record (ID: ${recordIds.salesforceContactId}) returned by the updateOrCreateContactAndAccount helper is missing a parent account record.`); - } - // Create the new Fleet website page view record. - await sails.helpers.salesforce.createHistoricalEvent.with({ - salesforceAccountId: recordIds.salesforceAccountId, - salesforceContactId: recordIds.salesforceContactId, - eventType: 'Intent signal', - intentSignal: 'Submitted the "Send a message" form', - eventContent: message, - }).intercept((err)=>{ - return new Error(`Could not create an historical event. Full error: ${require('util').inspect(err)}`); - }); - }).exec((err)=>{// Use .exec() to run the salesforce helpers in the background. - if(err) { - sails.log.warn(`Background task failed: When a user submitted a contact form message, a contact/account/historical event could not be created/updated in the CRM for this email address: ${emailAddress}. Full error: ${require('util').inspect(err)}`); - } - return; - });//_∏_ - } };