Home Bulk Enabled Triggers in Salesforce

Bulk Enabled Triggers in Salesforce:

it is strongly recommended that you make it bulk enabled, so that the trigger can handle number of records whcih can be inserted/updated/deleted through data loader or any other data migration tool.

Here is the Bulk trigger Example:

Trigger myTrigger on Account(after update) { Set <Id> setAccId = new Set<Id>(); for(Account a: Trigger.new) { if(a.isActive) setAccId.add(a.Id);//set always contains distinct Ids } list <Opportunity> lstOpp = [select Id, StageName from Opportunity where AccountId in : setAccId]; for(Integer i = 0; i < lstOpp.size(); i++) { lstOpp[i].StageName = "Learning"; } if(lstOpp.size() > 0) update lstOpp; }

Leave a Comment