From e1716d14846c245fa66d992ea12b51bfa9d9ae98 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 12 Jul 2024 15:34:15 -0500 Subject: [PATCH] Update create lead helper --- api/helpers/salesforce/create-lead.js | 34 ++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/api/helpers/salesforce/create-lead.js b/api/helpers/salesforce/create-lead.js index 7f7e28b..0fa11c7 100644 --- a/api/helpers/salesforce/create-lead.js +++ b/api/helpers/salesforce/create-lead.js @@ -30,6 +30,7 @@ module.exports = { 'Website - Sign up', 'Website - Waitlist', 'Website - swag request', + 'Outbound - Dripify', ], }, primaryBuyingSituation: { type: 'string', isin: ['eo-it', 'eo-security', 'mdm', 'vm'] }, @@ -72,6 +73,35 @@ module.exports = { }).intercept((err)=>{ return new Error(`When attempting to create a Lead record using an exisitng Account record (ID: ${salesforceAccountId}), An error occured when retreiving the specified record. Error: ${err}`); }); + let salesforceAccountOwnerId = accountRecord.OwnerId; + // If the account record is owned by the integrations admin user and is not the account where unenriched contacts go, we'll round robin it and reassign it to an AE. + if(salesforceAccountOwnerId === '0054x00000735wDAAQ' && salesforceAccountId !== '0014x000025JC8DAAW') { + // Get all round robin users. + let roundRobinUsers = await salesforceConnection.sobject('User') + .find({ + AE_Round_robin__c: true,// eslint-disable-line camelcase + }); + // Get the user with the earliest round robin timestamp. + let userWithEarliestAssignTimeStamp = _.sortBy(roundRobinUsers, 'AE_Account_Assignment_round_robin__c')[0]; + + let today = new Date(); + let nowOn = today.toISOString().replace('Z', '+0000'); + // Update the salesforceAccountOwnerId value to be the ID of the next user in the round robin. + salesforceAccountOwnerId = userWithEarliestAssignTimeStamp.Id; + // Update this user to put them at the bottom of the round robin list. + await salesforceConnection.sobject('User') + .update({ + Id: salesforceAccountOwnerId, + // eslint-disable-next-line camelcase + AE_Account_Assignment_round_robin__c: nowOn + }); + // Reassign the account to the new owner. + await salesforceConnection.sobject('Account') + .update({ + Id: salesforceAccountId, + OwnerId: salesforceAccountOwnerId + }); + } let primaryBuyingSituationValuesByCodename = { 'vm': 'Vulnerability management', @@ -97,13 +127,11 @@ module.exports = { // Information from contact record: FirstName: contactRecord.FirstName, LastName: contactRecord.LastName, - Email: contactRecord.Email, - Website: contactRecord.Website, of_hosts__c: numberOfHostsToSet,// eslint-disable-line camelcase Primary_buying_scenario__c: primaryBuyingSituationToSet,// eslint-disable-line camelcase LinkedIn_profile__c: contactRecord.LinkedIn_profile__c,// eslint-disable-line camelcase // Information from the account record: - OwnerId: accountRecord.OwnerId + OwnerId: salesforceAccountOwnerId }); }).intercept((err)=>{ return new Error(`Could not create new Lead record. Error: ${err}`);