You need to sign in to do that
Don't have an account?
Nandhini Govindraj
Sum all revenue of child accounts tp parent in account hierarchy
Hi
I have created a field Total Annual Revenue .
Result should be lik
Parent Ann revenue-5 total ann rev-12
Child Ann rev-2 total Ann Rev-7
Grant Child Ann rev-5 total Ann Rev-0
For this i used this code
trigger TotalAnnualRevenueChildAccount on Account (after insert,after update) {
Set<Id> accids=new Set<Id>();
if(trigger.isinsert || trigger.isupdate && trigger.isafter){
for(Account acc:trigger.new){
accids.add(acc.Id);
}
Map<Id,Account> maccid=new Map<Id,Account>();
for(AggregateResult ar:[select Id,sum(AnnualRevenue)TotalAnnRev from Account where ParentId=:accids Group by Id]){
Account ac=new Account();
ac.Id=(Id)ar.get('Id');
ac.Total_AnnualRevenue__c=(Double)ar.get('TotalAnnRev');
maccid.put(ac.Id,ac);
}
update maccid.values();
}
}
I am not getting the result as i mention above..
I have created a field Total Annual Revenue .
Result should be lik
Parent Ann revenue-5 total ann rev-12
Child Ann rev-2 total Ann Rev-7
Grant Child Ann rev-5 total Ann Rev-0
For this i used this code
trigger TotalAnnualRevenueChildAccount on Account (after insert,after update) {
Set<Id> accids=new Set<Id>();
if(trigger.isinsert || trigger.isupdate && trigger.isafter){
for(Account acc:trigger.new){
accids.add(acc.Id);
}
Map<Id,Account> maccid=new Map<Id,Account>();
for(AggregateResult ar:[select Id,sum(AnnualRevenue)TotalAnnRev from Account where ParentId=:accids Group by Id]){
Account ac=new Account();
ac.Id=(Id)ar.get('Id');
ac.Total_AnnualRevenue__c=(Double)ar.get('TotalAnnRev');
maccid.put(ac.Id,ac);
}
update maccid.values();
}
}
I am not getting the result as i mention above..
try with below code.
If this helps, Please mark it as best answer.
Thanks!!