You need to sign in to do that
Don't have an account?

Help Bulkifying Trigger
Hi All,
I have the following trigger to get a sum of all the opportunity amount under an account(as we have advanced multi currency enabled so trying to create a custom roll up summary field).
How to bulkify this trigger?Plz help.
trigger tgr_change_in_amount on Opportunity (after insert,after update,before delete) {
for (Opportunity opp: Trigger.new) {
if(opp.accountid != null){
Integer amt;
AggregateResult[] groupedResults = [SELECT SUM(Amount)aver FROM Opportunity where accountid =:opp.accountid];
for (AggregateResult ar : groupedResults) {
amt = Integer.valueOf(ar.get('aver'));
}
List<Account>lstAccount = new List<Account>();
lstAccount = [select Total_Amt_of_Open_Opportunities__c from Account where id=:opp.accountid];
lstAccount[0].Total_Amt_of_Open_Opportunities__c = amt;
update lstAccount;
}
}
}
Something like this should work.. Pls check for syntactical errors, just wrote this on the fly