As we have discussed in previous posts what trigger is,when to use it or not to use it,it’s context variables,events.
As moving forward it’s time to learn about bulkify trigger.The term bulkify trigger specifies the trigger which can process large number of records efficiently and most importantly without hitting Governer Limits of Salsesforce.It is one of the best practises of Salsesforce that you should always write bulkify trigger.
There is sacenario which helps you to understand why it is one of the best practises, triggers operate on one record if the action that fired the trigger originates from the user interface. But if the origin of the action is bulk DML or the API, the trigger operates on multiple records rather than single record which will hit the governer limit.
From above we got an idea about what the bulkify trigger is. Why it is one of the best practices of Salsesforce.Now the question is How to write bulkify triggers:-
Use map in writting trigger which help to reduce loop within loop
Use Set inspite of list as list can hold duplicate values
Put SOQL query directly in for loop condtion without using list to get query result and then iteration of list.