Update customer's salesforce account id when falling back to the contact
Problem
In https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/2816 the fallback to the contact in case the customer's salesforce_account_id
is empty was evaluated along the way and it resulted in this comment. TLDR: it might be a good idea to update the customer's salesforce_account_id
in case there was a fallback to the contact (this can be an existing one or even a newly created one). So here's the issue to suggest this:
When looking for the Salesforce account id of a customer and the salesforce_account_id
field is empty, there is a fallback to the Salesforce contact in place (here). But the customer object is not updated with that information in case the contact returns it.
This is also the case when creating a new contact as a fallback in the Salesforce::BaseOpportunityService that is used by Salesforce::CreateOpportunityService
and Salesforce::UpdateOpportunityService
.
@jbrennan1
also provided this information:
a quick overview / thoughts on how SFDC Account, Contact, Opportunity and Opportunity Contact Roles all work:
- Establish the SFDC Account Id that ALL of the remaining objects will relate up to. @cwiesner the improvement you made to make sure we are ensuring the Account Id is populated looks great! We need to make sure that all steps use the same Account Id.
- Insert the Contact with AccountId = the Account's Id.
- Insert the Opportunity with the AccountId = the Account's Id.
- Insert the Opportunity Contact Role with OpportunityId = Inserted Opp's Id and ContactId = Inserted Contact's Id.
Technically parts 2 and 3 can be switched in the order. Tell me if there are any more questions.
Proposal
After falling back to the Salesforce contact when the customer's salesforce_account_id
is empty, update it with the contact's AccountId
.
Result
Consistent data and less queries since the field will be updated.
Next steps (if any)
How will we measure success?
Availability & Testing
We should consider writing an automated test to test detection of these cases and test the resulting action(s).