diff --git a/website/api/controllers/save-questionnaire-progress.js b/website/api/controllers/save-questionnaire-progress.js index 90df2bb29da..9ff49c958c2 100644 --- a/website/api/controllers/save-questionnaire-progress.js +++ b/website/api/controllers/save-questionnaire-progress.js @@ -208,14 +208,20 @@ module.exports = { }//fi // Only update CRM records if the user's psychological stage changes. - if(psychologicalStage !== userRecord.psychologicalStage){ - await sails.helpers.salesforce.updateOrCreateContactAndAccount.with({ - emailAddress: this.req.me.emailAddress, - firstName: this.req.me.firstName, - lastName: this.req.me.lastName, - primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined, - organization: this.req.me.organization, - psychologicalStage, + if(psychologicalStage !== userRecord.psychologicalStage) { + // Use setImmediate to queue CRM updates. + // [?]: https://nodejs.org/api/timers.html#setimmediatecallback-args + require('timers').setImmediate(async ()=>{ + await sails.helpers.salesforce.updateOrCreateContactAndAccount.with({ + emailAddress: this.req.me.emailAddress, + firstName: this.req.me.firstName, + lastName: this.req.me.lastName, + primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined, + organization: this.req.me.organization, + psychologicalStage, + }).catch((err)=>{ + sails.log.warn(`When a user (email: ${this.req.me.emailAddress} submitted a step of the get started questionnaire, a Contact and Account record could not be created/updated in the CRM. Full error:`, err); + }); }); } // TODO: send all other answers to Salesforce (when there are fields for them)