Skip to content

Commit

Permalink
Update create lead helper
Browse files Browse the repository at this point in the history
  • Loading branch information
eashaw committed Jul 12, 2024
1 parent 3f841f1 commit e1716d1
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions api/helpers/salesforce/create-lead.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
Expand Down Expand Up @@ -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',
Expand All @@ -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}`);
Expand Down

0 comments on commit e1716d1

Please sign in to comment.