public class Contracts_Trigger {
//The total contract revenues for an account should be auto summed as a field on the account.
public static void ConRevenue(List<Contract> contractList){
List<Account> accList=new List<Account>();
Set<Id> conIds = new Set<Id>();
Decimal sum=0;
for(Contract c:contractList){
conIds.add(c.AccountId);
}
accList=[select Id,Name,AnnualRevenue from Account where Id in:conIds];
For(Account a:accList){
sum=sum+a.AnnualRevenue;
System.debug('AnnualRevenue Sum:'+sum);
a.totalPipeline__c=sum;
}
update accList;
}
}
You need to write a trigger on Contract object which will sum up the amount of all related contract records. The summed up amount you can put on Account Field.
Check the sample roll-up summery code here for reference: https://github.com/amitastreait/Rollup-Summary-Trigger/blob/master/Attachment_Trigger.java
Let me know if this helps.
**Please mark this as best answer if this answers your query.**
Thanks,
Manish Choudhari
14x Certified Salesforce Architect
Certification link: http://certification.salesforce.com/certification-detail-print?conId=003G000002gRrrEIAS
My Blog: http://sfdcfacts.com/
Youtube Channel: https://www.youtube.com/SFDCFacts
LinkedIn: https://www.linkedin.com/in/manish-choudhary/
Trailhead: https://trailhead.salesforce.com/en/me/manish-choudhari
Twitter: https://mobile.twitter.com/manish_sfdc
Try this