
3 个回答

Hi Vetriselvan,Please go through below trigger code along with comments. This will give you idea as to bulkifying the code.The DML operation is out of For loop.You can refer to best practices:https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code
Thanks,PratikP.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.Trigger oppaccupdate on Account(after update){
list<opportunity> opplistupdate=new list<opportunity>();
list<opportunity> opplist=new list<opportunity>();
for(account a:trigger.new) {
IF (a.industry=='Agriculture') {
opplist= [select id,stagename,accountid from opportunity where accountid=:a.id];
}
}
for (opportunity opp:opplist) {
If(opp.stagename!=null) {
opp.stagename= 'Need Analysis';
opplistupdate.add(opp); // Add the record to update in the list within for loop
}
}
update opplistupdate; // Update the list outside the for loop i.e. any DML operation, out of for loop to avoid governor limits