+ Start a Discussion

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?​​​​​​​

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

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.