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
jagdish nikam 9jagdish nikam 9 

Calculate sum of contact fields and display on account page

Hi All, 

If i have cusotm field "ConAmount" on contact object which hold any number or any currency and i just want to display a sum of that field for all contact on account page. How can i acheive this? Is it possible using workflow if not then please provide a trigger code for the same.
Peter FribergPeter Friberg
Create a trigger on Contact that triggers on "after insert", "after update" and "after delete".
Find all related account ids.
Do a soql query of all those accounts with related contacts.
Calculate the new sum for each account by summing all contacts for each account.
Update only those accounts where the sum actually changed.