Best Answer · By JanBask Salesforce Expert
Answered on Mar 2, 2020
As per salesforce recommended best practices for apex trigger, developers should write a trigger code in such a way that code can process bulk of records and not only single records. The main benefit of bulkifying is that it will process more than one record at a time and we can perform the DML operation on a batch of records and also we can avoid hitting the governor limits.
For example , If you notice the below mentioned poorly written code and not follow the best practices of salesforce, this trigger can only process the first record of trigger.ew collection as we already mentioned first record in code.
trigger account trigger on Account (before insert, before update) {
//This trigger can only process the first record in the Trigger.new collection
//But if more than 1 Account initiated this trigger, those additional records
//will not be processed
Account acc = Trigger.new[0];
List contacts = [select id, salutation, firstname, last name
from Contact where accountId = :acct.Id];
}