Notes
All triggers are bulk triggers by default, and can process multiple records at a time. You should always plan on processing more than one record at a time.
Single:
The following trigger assumes that only one record caused the trigger to fire. This trigger doesn’t work on a full record set when multiple records are inserted in the same transaction.
trigger MyTriggerNotBulk on Account(before insert) {
Account a = Trigger.New[0];
a.Description = 'New description';
}
Bulk:
This example is a modified version of MyTrigger. It uses a for loop to iterate over all available sObjects. This loop works if Trigger.New contains one sObject or many sObjects.
trigger MyTriggerBulk on Account(before insert) {
for(Account a : Trigger.New) {
a.Description = 'New description';
}
}