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
ABHIJEET BUDKEABHIJEET BUDKE 

Same logic trigger on multiple objects

Hi All,
 I have one master (obj A) and 3 child object (ObjB,ObjC,ObjD) in look up relationship. Each child have Amt field and Mast have Final_Amount(ie sum of Amt all childs record) . I want whenever new record is created in any of child object sum of Amt field is get added\updated in master field.
Example
ObjB - 3 records Sum (Amt) = 40
ObjC - 2 records Sum (Amt) = 45
ObjD - 4 records Sum (Amt) = 50

So value in ObjA Final_Amounts should be  (40+45+50)= 135
Now one more entry is added in ObjD with Value 10 Then Final_Amounts  should be 145
First thought for this is Trigger on each 3 child object. But implementation\logic will be same for 3 trigger.(Want to avoid code same code repetition)
Is there any way I can achieve this with Trigger ?

Also please suggest some other way is there to achieve this.
Andries.NeyensAndries.Neyens
Maybe with the function: getPopulatedFieldsAsMap() ? and make your code dynamic

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm