You need to sign in to do that
Don't have an account?
anji punyamanthula
I want to sum of all the opprtunities amounts and display on Account object how to do that can any help me in that
I tried below code but i'm not getting o/p
Apex trigger:
trigger Rollup_Acc on Opportunity (After insert,After update,After delete,after undelete) {
if(trigger.isinsert && trigger.isupdate && trigger.isdelete && trigger.isundelete){
List<Account> accs=new List<Account>();
Set<Id> ids=new Set<Id>();
for(opportunity o:trigger.new){
ids.add(o.AccountId);
}
decimal sum;
for(Account acc :[select id,name,Amount__c,(select id,name,amount from opportunities ) from Account where id =:ids]){
sum=0;
for(opportunity op:acc.opportunities){
sum+=op.Amount;
}
acc.AnnualRevenue=sum;
accs.add(acc);
}
update accs;
}
}
Apex trigger:
trigger Rollup_Acc on Opportunity (After insert,After update,After delete,after undelete) {
if(trigger.isinsert && trigger.isupdate && trigger.isdelete && trigger.isundelete){
List<Account> accs=new List<Account>();
Set<Id> ids=new Set<Id>();
for(opportunity o:trigger.new){
ids.add(o.AccountId);
}
decimal sum;
for(Account acc :[select id,name,Amount__c,(select id,name,amount from opportunities ) from Account where id =:ids]){
sum=0;
for(opportunity op:acc.opportunities){
sum+=op.Amount;
}
acc.AnnualRevenue=sum;
accs.add(acc);
}
update accs;
}
}
All Answers
No need to write trigger for this.
Just create one roll up summary field on Account and select Summarized object as Opportunity then select Roll-Up type as "SUM" and select field to agreegate as "Amount" and you should be good to GO !!
Let me know for any issues.
Thanks
Arpit
Please mark this answer as SOLVED and BEST ANSWER if it helps you.
Best way to implement this by rollup summary field.
There is small mistake in your trigger code.
just change one thing from && to || it will like this.
Please mark this answer as SOLVED and BEST ANSWER if it helps you.
Regards,
Yogesh More
Salesforce consultant || Salesforce Developer
more.yogesh422@gmail.com || yogeshsfdc11@gmail.com
www.yogeshmore.com || Skype:-yogesh.more44
Please check below code once :
Hope it helps you.
Please mark it as best answer if the above information is informative.
In case of any other assistance please let me know.
Thanks,
Varaprasad
Salesforce Developer
more: varaprasad4sfdc@gmail.com
Try following code.
let us know if it helps you.
Regards,
Yogesh
I have tested my code it's working 100% correct , Please use
Please Mark as Best Answer!!!!!
Regards
Mukesh
Plz check once below code :
Thanks
Varaprasad
Please use this code, it's working 100% correct:-
Please MARK AS A BEST ANSWER!!!!
Regards
Mukesh