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 ?
> 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
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/
> 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
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.