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
Saravana RavikumarSaravana Ravikumar 

I have a standard object that needs to have an amount rolled up from a custom object that is in a lookup relationship. To achieve this , Why should I write a trigger on the child object instead of writing trigger on the parent object ?

SwethaSwetha (Salesforce Developers) 
HI Ravi,

> When you write a trigger on the child object, you only need to query the child object, which is likely to be much smaller than the parent object. This can improve performance, especially if you are rolling up a large amount of data.

> If you write a trigger on the parent object, you need to make sure that you only update the parent object if the corresponding child object has been updated. This can be difficult to do, especially if you are using a complex lookup relationship. If you write a trigger on the child object, you can be sure that the parent object will only be updated if the corresponding child object has been updated.

> If you write a trigger on the parent object, you need to make sure that you update the parent object in a consistent way. This can be difficult to do, especially if you are updating multiple child objects. If you write a trigger on the child object, you can be sure that the parent object will be updated in a consistent way.

See related: https://www.coral.team/Blog/Post/automation-on-Child-Lookup-Relationship-wont-trigger-if-Parent-is-deleted

If this information helps, please mark the answer as best. Thank you
Arun Kumar 1141Arun Kumar 1141
Hello Saravana,

There are two possiblities that you apply trigger on child or parent, but it is suggested to apply trigger on child object because whenever a record will be inserted or updated corresponding parent record will be updated in that case. But if you apply trigger on parent than if child record undergoes some changes, related parent record field will not get updated. Rest if you want to create roll-up field than you can use some other ways too.
Go with this link:-
https://www.salesforceben.com/4-ways-to-create-roll-up-summary-fields-on-lookup-relationships-in-salesforce/

Hope this will help!
Thanks.