diff --git a/website/api/controllers/deliver-contact-form-message.js b/website/api/controllers/deliver-contact-form-message.js index a27b6125cff2..bf0a8030fd8e 100644 --- a/website/api/controllers/deliver-contact-form-message.js +++ b/website/api/controllers/deliver-contact-form-message.js @@ -71,12 +71,12 @@ module.exports = { `Name: ${firstName + ' ' + lastName}, Email: ${emailAddress}, Message: ${message ? message : 'No message.'}` }); - sails.helpers.salesforce.updateOrCreateContactAndAccountAndCreateLead.with({ + sails.helpers.salesforce.updateOrCreateContactAndAccount.with({ emailAddress: emailAddress, firstName: firstName, lastName: lastName, leadSource: 'Website - Contact forms', - leadDescription: `Sent a contact form message: ${message}`, + description: `Sent a contact form message: ${message}`, }).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 lead/contact could not be updated in the CRM for this email address: ${emailAddress}.`, err); diff --git a/website/api/controllers/deliver-talk-to-us-form-submission.js b/website/api/controllers/deliver-talk-to-us-form-submission.js index 2a307b0c6354..6dd53f88bef3 100644 --- a/website/api/controllers/deliver-talk-to-us-form-submission.js +++ b/website/api/controllers/deliver-talk-to-us-form-submission.js @@ -74,21 +74,36 @@ module.exports = { throw 'invalidEmailDomain'; } - - sails.helpers.salesforce.updateOrCreateContactAndAccountAndCreateLead.with({ - emailAddress: emailAddress, - firstName: firstName, - lastName: lastName, - organization: organization, - numberOfHosts: numberOfHosts, - primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined, - leadSource: 'Website - Contact forms', - leadDescription: `Submitted the "Talk to us" form and was taken to the Calendly page for the "${numberOfHosts > 700 ? 'Talk to us' : 'Let\'s get you set up!'}" event.`, - }).exec((err)=>{ - if(err) { - sails.log.warn(`Background task failed: When a user submitted the "Talk to us" form, a lead/contact could not be updated in the CRM for this email address: ${emailAddress}.`, err); - } - }); + if(numberOfHosts >= 700){ + sails.helpers.salesforce.updateOrCreateContactAndAccountAndCreateLead.with({ + emailAddress: emailAddress, + firstName: firstName, + lastName: lastName, + organization: organization, + numberOfHosts: numberOfHosts, + primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined, + leadSource: 'Website - Contact forms', + leadDescription: `Submitted the "Talk to us" form and was taken to the Calendly page for the "Talk to us" event.`, + }).exec((err)=>{ + if(err) { + sails.log.warn(`Background task failed: When a user submitted the "Talk to us" form, a lead/contact could not be updated in the CRM for this email address: ${emailAddress}.`, err); + } + }); + } else { + sails.helpers.salesforce.updateOrCreateContactAndAccount.with({ + emailAddress: emailAddress, + firstName: firstName, + lastName: lastName, + organization: organization, + primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined, + leadSource: 'Website - Contact forms', + description: `Submitted the "Talk to us" form and was taken to the Calendly page for the "Let\'s get you set up!" event.`, + }).exec((err)=>{ + if(err) { + sails.log.warn(`Background task failed: When a user submitted the "Talk to us" form, a lead/contact could not be updated in the CRM for this email address: ${emailAddress}.`, err); + } + }); + } return; } diff --git a/website/api/helpers/salesforce/update-or-create-contact-and-account-and-create-lead.js b/website/api/helpers/salesforce/update-or-create-contact-and-account-and-create-lead.js index a9c3e342745f..aa13206c4896 100644 --- a/website/api/helpers/salesforce/update-or-create-contact-and-account-and-create-lead.js +++ b/website/api/helpers/salesforce/update-or-create-contact-and-account-and-create-lead.js @@ -73,6 +73,7 @@ module.exports = { primaryBuyingSituation, psychologicalStage, leadSource, + description: leadDescription, }); await sails.helpers.salesforce.createLead.with({ diff --git a/website/api/helpers/salesforce/update-or-create-contact-and-account.js b/website/api/helpers/salesforce/update-or-create-contact-and-account.js index c07e1918d7d2..aea76fd28cad 100644 --- a/website/api/helpers/salesforce/update-or-create-contact-and-account.js +++ b/website/api/helpers/salesforce/update-or-create-contact-and-account.js @@ -17,6 +17,7 @@ module.exports = { firstName: { type: 'string', required: true }, lastName: { type: 'string', required: true }, organization: { type: 'string' }, + description: { type: 'string' }, primaryBuyingSituation: { type: 'string' }, psychologicalStage: { type: 'string', @@ -51,7 +52,7 @@ module.exports = { }, - fn: async function ({emailAddress, linkedinUrl, firstName, lastName, organization, primaryBuyingSituation, psychologicalStage, leadSource}) { + fn: async function ({emailAddress, linkedinUrl, firstName, lastName, organization, primaryBuyingSituation, psychologicalStage, leadSource, description}) { // Return undefined if we're not running in a production environment. if(sails.config.environment !== 'production') { sails.log.verbose('Skipping Salesforce integration...'); @@ -95,6 +96,9 @@ module.exports = { if(psychologicalStage) { valuesToSet.Stage__c = psychologicalStage;// eslint-disable-line camelcase } + if(description) { + valuesToSet.Description = description; + } let existingContactRecord; // Search for an existing Contact record using the provided email address or linkedIn profile URL. @@ -111,6 +115,10 @@ module.exports = { } if(existingContactRecord) { + // If a description was provided and the contact has a description, append the new description to it. + if(description && existingContactRecord.Description) { + valuesToSet.Description = existingContactRecord.Description + '\n' + description; + } // console.log(`Exisitng contact found! ${existingContactRecord.Id}`); // If we found an existing contact, we'll update it with the information provided. salesforceContactId = existingContactRecord.Id;