You need to sign in to do that
Don't have an account?
Sidbht
Hi There, Can anyone help me with rollup summary trigger on Accounts and Order. I want to populate the Count of Orders on Account and when Order is deleted Account Count should update. Thanks in advance.
Hi There, Can anyone help me with rollup summary trigger on Accounts and Order. I want to populate the Count of Orders on Account and when Order is deleted Account Count should update. Thanks in advance.
This is sample code count of contact for account :
and change to as you required.
Thanks,
Harish R.
All Answers
This is sample code count of contact for account :
and change to as you required.
Thanks,
Harish R.
Please see the below code:
Trigger count_no_of_Orders on Order (after insert,after delete,after update,after undelete) {
set<id> accountIdSet=new set<id>();
for(order od:trigger.isDelete?trigger.old:trigger.new){
if(od.accountid!=null){
accountIdSet.add(od.accountid);
}
}
map<string,integer> mapdata=new map<string,integer>();
for(AggregateResult ar:[select accountid ai,count(id) oid from order where check__c=true and accountid in:accountIdSet group by accountid]){
mapdata.put(string.valueof(ar.get('ai')), integer.valueOf(ar.get('oid')));
}
list<account> acclist=new list<account>();
for(string ids:accountIdSet){
integer n=0;
if(mapdata.containsKey(ids))
n=mapdata.get(ids);
account acc=new account(id=ids,Number_Of_Orders__c=n);
acclist.add(acc);
}
if(acclist.size()>0)
dataBase.update(accList);
}
Please mark your problem as solved if this will fulfill your requirement.
Thanks,
Duke_Sfdc