Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How to create field on account to act as rollup summry field?

Asked by Amit Verma Apr 16, 2021 403 views 1 answer
Share

About this question

 I am trying to develop an apex trigger which will give me total amount of all child objects amount and it will act as a Roll up Summary field. I am getting below error,

Variable does not exist: AccountID at line 25 column 23

Trigger

trigger RollUpField on Contact (after insert,after update,after delete,after undelete) { Mapcounter=new Map(); Set cids=new Set(); if(Trigger.isInsert||Trigger.isUpdate) { for(Contact c:Trigger.new) { cids.add(c.AccountID); } } if(Trigger.isDelete) { for(Contact c:Trigger.old) { cids.add(c.AccountID); } } for(AggregateResult q:[Select AccountID,Sum(Count__c)Amount from Contact where AccountID IN:cids group by AccountID]);{ counter.put((ID)q.get(AccountID),(Double)q.get(Amount)); } List acc=new List(); for(Account a:[Select id,Total_Amount__c from Account where ID IN:Cids]) { Double total=counter.get(a.id); a.Total_Amount__c =total; acc.add(a); } update acc; }


Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.