Skip to content

Commit

Permalink
Update salesforce helper
Browse files Browse the repository at this point in the history
  • Loading branch information
eashaw committed May 6, 2024
1 parent f7fbf69 commit 2d184f1
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions api/helpers/salesforce/update-or-create-contact-and-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,21 @@ module.exports = {
// Special sacraficial meat cave where the contacts with no organization go.
// https://fleetdm.lightning.force.com/lightning/r/Account/0014x000025JC8DAAW/view
salesforceAccountId = '0014x000025JC8DAAW';
salesforceAccountOwnerId = '0054x00000735wDAAQ';
salesforceAccountOwnerId = '0054x00000735wDAAQ';// « "Integrations admin" user.
} else {
let existingAccountRecord = await salesforceConnection.sobject('Account')
.findOne({
'Website': enrichmentData.employer.emailDomain,
// 'LinkedIn_company_URL__c': enrichmentData.employer.linkedinCompanyPageUrl // TODO: if this information is not present on an existing account, nothing will be returned.
});
// console.log(existingAccountRecord);
if(existingAccountRecord) {
if(existingAccountRecord && salesforceAccountId === '0054x00000735wDAAQ') {
// Store the ID of the Account record we found.
salesforceAccountId = existingAccountRecord.Id;
salesforceAccountOwnerId = existingAccountRecord.OwnerId;
// console.log('exising account found!', salesforceAccountId);
} else {


// If we didn't find an existing record, or found one onwned by the integrations admin, we'll round robin it between the AE's Salesforce users.
let roundRobinUsers = await salesforceConnection.sobject('User')
.find({
AE_Round_robin__c: true,// eslint-disable-line camelcase
Expand All @@ -103,34 +102,45 @@ module.exports = {

let today = new Date();
let nowOn = today.toISOString().replace('Z', '+0000');

// Update the accountOwnerId value to be the ID of the next user in the round robin.
salesforceAccountOwnerId = userWithEarliestAssignTimeStamp.Id;

// Update this user to putthem atthe bottom of the round robin list.
// 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
});
// If no existing account record was found, create a new one.
let newAccountRecord = await salesforceConnection.sobject('Account')
.create({
OwnerId: salesforceAccountOwnerId,
Account_Assigned_date__c: nowOn,// eslint-disable-line camelcase
// eslint-disable-next-line camelcase
Current_Assignment_Reason__c: 'Inbound Lead',// TODO verify that this matters. if not, do not set it.
Prospect_Status__c: 'Assigned',// eslint-disable-line camelcase

Name: enrichmentData.employer.organization,// IFWMIH: We know organization exists
Website: enrichmentData.employer.emailDomain,
LinkedIn_company_URL__c: enrichmentData.employer.linkedinCompanyPageUrl,// eslint-disable-line camelcase
NumberOfEmployees: enrichmentData.employer.numberOfEmployees,
});
salesforceAccountId = newAccountRecord.id;

if(existingAccountRecord){
// If we found an existing Account record owned by the integrations admin user account, reassign it to the new owner.
salesforceAccountId = existingAccountRecord.Id;
await salesforceConnection.sobject('Account')
.update({
Id: salesforceAccountId,
OwnerId: salesforceAccountOwnerId
});
} else {
// If no existing account record was found, create a new one.
let newAccountRecord = await salesforceConnection.sobject('Account')
.create({
OwnerId: salesforceAccountOwnerId,
Account_Assigned_date__c: nowOn,// eslint-disable-line camelcase
// eslint-disable-next-line camelcase
Current_Assignment_Reason__c: 'Inbound Lead',// TODO verify that this matters. if not, do not set it.
Prospect_Status__c: 'Assigned',// eslint-disable-line camelcase

Name: enrichmentData.employer.organization,// IFWMIH: We know organization exists
Website: enrichmentData.employer.emailDomain,
LinkedIn_company_URL__c: enrichmentData.employer.linkedinCompanyPageUrl,// eslint-disable-line camelcase
NumberOfEmployees: enrichmentData.employer.numberOfEmployees,
});
salesforceAccountId = newAccountRecord.id;
}//fi
// console.log('New account created!', salesforceAccountId);
}
}
}//fi
}//fi



Expand All @@ -153,7 +163,7 @@ module.exports = {
});
} else {
existingContactRecord = undefined;
}
}//fi

let salesforceContactId;
let valuesToSet = {};
Expand Down Expand Up @@ -197,7 +207,7 @@ module.exports = {
// console.log(newContactRecord);
salesforceContactId = newContactRecord.id;
// console.log(`New contact record created! ${salesforceContactId}`);
}
}//fi


return {
Expand Down

0 comments on commit 2d184f1

Please sign in to comment.