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
Michelle GrantMichelle Grant 

Best practice question: Parent update triggering update on children

This is not a how to question, but a best practice/opinion question. I have a request to update a calculation on specific child records when a field on a parent record is updated. I am hesitant to do this since then the children records will go through the entire save procedure (including a good amount of Apex code), so it would add a bit more processing to the Apex transaction. My question is, when would you go ahead with this request vs pushing back and trying to find another solution (i.e. batch update of the child records every hour/night, new business process-- after updating the parent, go and check this checkbox on the children, . . . )? In general there shouldn't be more than 5 child records per parent that need to be updated.
Best Answer chosen by Michelle Grant
Shashikant SharmaShashikant Sharma
Yes I meant After Update as we are updating child records here. Whenever there is an DML on any other entity than the entity in trigger context we go for After Update.
About the rollup calculations you are right. The Trigger will fire on parent record if there is a modification on the field of child record that feeds to the parent as roll up only.

I hope above answers your question.

Thanks
Shashikant
 

All Answers

Shashikant SharmaShashikant Sharma

Hi Michelle,

I would suggest to do it in After Insert Trigger of Parent Record as there are only 5 childs per parent so should not be an issue as Triggers work in chunk of 200 so even at bulk case scenario you will only have 1000 child records to update. This is the general and best practice for this scenario. 

One thing I would like you to see is possiblity of Formula field on child object so you dont even require a Trigger.

Thanks

Shashikant

 

Michelle GrantMichelle Grant
Thanks. Do you mean After Update? The parent records already exist. Good to hear you don't think it's a huge issue. I had been thinking updating the children would retrigger the parent since we have rollups from the child to the parent, but I realized that wouldn't happen since none of those rollup values would be changing. From what I learned, at least, the parent would only go through the save procedure again if the rollup summary field values change. If they stay the same, the parent will not go through save prodedure again. Correct?

I thought about a formula field, but I don't think that would be best for this use case. Thanks for the idea though.
Shashikant SharmaShashikant Sharma
Yes I meant After Update as we are updating child records here. Whenever there is an DML on any other entity than the entity in trigger context we go for After Update.
About the rollup calculations you are right. The Trigger will fire on parent record if there is a modification on the field of child record that feeds to the parent as roll up only.

I hope above answers your question.

Thanks
Shashikant
 
This was selected as the best answer