Non-Bulkified code:
It can not process large set of data and eventually can hit governor limit because it works on one record.
For example: It can process only one (first) account record from the Trigger.new collection, but if more than one account has initiated this trigger, then those additional records will not be processed.
trigger nonBulkifiedTrigger on Account (before insert, before update) {
//It can get only first record from the collection
Account acct = Trigger.new[0];
List<Contact> contacts = [Select id, firstname, lastname, email
From Contact
Where accountId = :acct.Id];
}
Bulkified Code:
It can process large set of data and escape governor limit because it works on list of records.
For example: It can process all account record from the Trigger.new collection.
trigger bulkifiedTrigger on Account (before insert, before update) {
//Loop through all records in the Trigger.new collection
for(Account a: Trigger.new){
//Concatenate the Name and billingState into the Description field
a.Description = a.Name + ':' + a.BillingState
}
}
It can not process large set of data and eventually can hit governor limit because it works on one record.
For example: It can process only one (first) account record from the Trigger.new collection, but if more than one account has initiated this trigger, then those additional records will not be processed.
trigger nonBulkifiedTrigger on Account (before insert, before update) {
//It can get only first record from the collection
Account acct = Trigger.new[0];
List<Contact> contacts = [Select id, firstname, lastname, email
From Contact
Where accountId = :acct.Id];
}
Bulkified Code:
It can process large set of data and escape governor limit because it works on list of records.
For example: It can process all account record from the Trigger.new collection.
trigger bulkifiedTrigger on Account (before insert, before update) {
//Loop through all records in the Trigger.new collection
for(Account a: Trigger.new){
//Concatenate the Name and billingState into the Description field
a.Description = a.Name + ':' + a.BillingState
}
}
No comments:
Post a Comment