function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger rollupopp on Opportunity (after delete,after update,after insert,after undelete) { set<ID>AccIds = new set<ID>(); if(trigger.isinsert || trigger.isundelete){ for(opportunity opp : trigger.new){ AccIds.add(opp.AccountId); } } if(trigger.isdelete){ for(opportunity opp : trigger.old){ AccIds.add(opp.AccountId); } } if(trigger.isupdate){ for(opportunity opp:trigger.new){ AccIds.add(opp.AccountId); if(trigger.oldmap.get(opp.id).AccountId != opp.AccountId && trigger.oldmap.get(opp.id).AccountId != null ){ AccIds.add(trigger.oldmap.get(opp.id).AccountId); } } } map<id,double> amtmap = new map<id,double>(); for(aggregateresult ag : [select AccountId ,SUM(Amount) SOA,count(id) cc from opportunity where AccountId in:AccIds group by AccountId]){ amtmap.put((ID)ag.get(‘AccountId’), double.valueof(ag.get(‘SOA’))); } list<account>acclist = new list<account>(); for(id iid : AccIds){ account acnt = new account(id=iid); if(amtmap.containskey(iid)){ acnt.Total_Amount__c = amtmap.get(iid); }else{ acnt.Total_Amount__c = 0; } acclist.add(acnt); } if(acclist.size()>0){ update acclist; } }
Try below code
If this information helps, please mark the answer as best. Thank you