function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matthew MarshMatthew Marsh 

Update Parent Account with Child Lookup

Hello all, thank you in advance! I have an interesting problem, and I am trying to work through it. 

I have two lookup fields on a child object of Account. One is for a US agent, and the other is for a World agent.  Depending on which one of these lookups is manually populated, I need to update a lookup field on the parent case with the correct lookup field from the child. The field on the parent account is essentially the top agent for the Account. I can build the validation as to which field's value will be used in the update.  

I originally tried to do this with a formula field on Account which worked, but the Lookup field on the account is being used in way too many other classes to remove and replace with a new field type. I have to be able to solve this with code, as I also cannot use process builder in this org. Any advice on how to start would be much appreciated! Thank you again!
Abhishek BansalAbhishek Bansal
Hi Matthew,

I understand your requirement that based on the value selected in the child object yoiu need to update a field on the parent object which can be easily done with the help of the trigger but in order to proceed we must know the data structure of your org. Please let us know the name of the fields on the child as well as the parent object and also the conditions like on what condition we need to update the field.

Thanks,
Abhishek  Bansal.
Matthew MarshMatthew Marsh
Hello Abhishek, thanks for taking a look at this!

I was incorrect in saying the child object is in fact a child. It is in fact just another object that has a lookup to the Account. On that note:

I have two fields, EU_Assignee and US_Assignee. They are both lookups to User, and live on Account_Supplemental. Basically this Object just allows us to add extra info to multiple accounts.  

-If US_Assignee is populated, update the Assignee__c Lookup field on Account with the US_Assignee.
-If US_Assignee AND EU_Assignee are populated, use US_Assignee.
-if EU_Assignee is the only field populated, use it.
-if both are blank, leave blank. 

should be inserted on creation of the Account_Supplemental, or if the US_Assignee or EU_Assignee are updated.

Thank you!