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
RJ12RJ12 

How to write trigger on roll-up summaries in Lookup?

Can you help me to write a trigger that captures the value of a number field in child records and calculates the total sum in the Parent record?​​​​​​​

​​​​​​​Example:
Parent: Account
Field: Total_Value__c

​​​​​​​Child: Contact
Field: Value__c

Parent record can have multiple child records. How can I sum up all the values in value__c from child records and save in Total_Value__c  in parent record using trigger?

Alain CabonAlain Cabon
@RJ12

You can write a trigger by yourself or use the Fawcett's generator for declarative lookup rollup summaries.  

Pros: a perfect generated code with just a few mouse clicks (declarative, zero code written).
Cons: you need to install a new package (lot of code) for just one roll-up summary at the end perhaps.

https://github.com/afawcett/declarative-lookup-rollup-summaries#packaged-release-history