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
Deb HalderDeb Halder 

How do I decide when to use on Parent or Child object when writing a trigger?

I would like to understand when to use trigger on Parent or Child, for example  trigger <trigger name> on <Parent/Child object>{}
If I am to update child field based on something changed on Parent field why would I write a trigger on Parent , similarly if I am updating child line items for Parent Opportunity why would I write Trigger on child object instead of Parent object ?
Ajay K DubediAjay K Dubedi
Hi Deb,

If you are changing in parent then the child is update. You can write the trigger on Parent.
Similarly, If you are changing in the child then Parent is updating. You can write the trigger on Child.

and If you are check condition of parent field with child field then update child. you can write the trigger on Parent.
similarly for child field.

Finally, you can decide based on the scenario.
 
1-Update Contact other phone field and populate it with the parent Account phone field.

 update contact other phone fields same with account phone field trigger write on "Account".
 
2-On Contact to update the Account Name field with contact Last Name, concatenated in the end. Example: If you create a Contact 
  whose FirstName='Sarthak' and LastName='Saxena' and the Accountname ='Tata', Then Account name must become 'TataSaxena'.
  
  update account name field adds with contact last name then you can write trigger on "Contact".  
 
Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi