Snippet 1:
trigger AccountValidationTrigger on Account(before update){
for(Account accObj: Trigger.new){
if(accObj.Some_Flag__c != TRUE){
accObj.addError('Some flag should be true');
}
}
}
Snippet 2:
trigger AccountValidationTrigger on Account(before update){
List<Account> errorAcctsList = new List<Account>();
for(Account accObj: Trigger.new){
if(accObj.Some_Flag__c != TRUE){
errorAcctsList.add(accObj);
}
}
for(Account accObj: errorAcctsList){
accObj.addError('Some flag should be true');
}
}
Given the above two code snippets, which of the above is a best practice to use in trigger when adding validation logic.
Most of the best practices for trigger bulkification are about reducing number of DML statements but I couldn't find any example on what is the best practice to follow in above situations.