You need to sign in to do that
Don't have an account?
Nandhini Govindraj
total revenue of all child accounts
I have created a field :Total Annual Revenue .
Result should be like
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
Result should be like
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
i have written code as below
trigger TotalAnnualRevenueChildAccount on Account (after insert,after update) {
List<Account> ac=new List<Account>();
Set<Id> accids=new Set<Id>();
for(Account acc:trigger.new){
accids.add(acc.Id);
if(accids != null){
List<Account> acclist = [Select Id, AnnualRevenue from Account Where ID IN :accIds];
for(Account acc: acclist){
acc. Total_AnnualRevenue__c+= acc.AnnualRevenue ;
ac.add(acc);
}
}
Update ac;
}
Can you help me in this
Thanks
List<Account> ac=new List<Account>();
Set<Id> accids=new Set<Id>();
for(Account acc:trigger.new){
accids.add(acc.Id);
if(accids != null){
List<Account> acclist = [Select Id, AnnualRevenue from Account Where ID IN :accIds];
for(Account acc: acclist){
acc. Total_AnnualRevenue__c+= acc.AnnualRevenue ;
ac.add(acc);
}
}
Update ac;
}
Can you help me in this
Thanks
Hey Nandhini,
Try to add the debug statement to check what is the value coming in the list.
then write it like this :-
If(list.size>0){
update acc;
}
Also you are using 'After Update' event, then this trigger will run in loop. Please remove that event first and then try.
Regards,
Priya Ranjan