I've written a trigger on Account object. When I upload records using Dataloader, or update them using Batch apex(200 batch size), this trigger executes on all records if there is no error. But, it misses the complete batch if there is an error while updating/inserting at-least one record.
Can someone give some direction on this?
Please note that accounts having no errors in the batch get updated/inserted, but trigger code is rolled-back on whole batch
Please find below the two versions of the trigger(before and after), both dont work:
VERSION -1
trigger accountScorerTrigger on Account (before insert, before update) {
if(Trigger.isUpdate || Trigger.isInsert) {
if(Utility.isFutureUpdate){
List<Account> accList = new List<Account>();
// Iterate through all records
for (Account newAccount:Trigger.new) {
Account tempAcc = new Account(id = newAccount.id);
tempAcc.Account_Score_History__c = 'TESTING RECORDS 3';
accList.add(tempAcc);
}
Utility.isFutureUpdate = false;
if(accList.size()>0){
//update accList;
Database.DMLOptions dml = new Database.DMLOptions();
dml.optAllOrNone = true;
database.update(accList,dml);
}
}
}
}
VERSION -2
trigger accountScorerTrigger on Account (before insert, before update) {
if(Trigger.isUpdate || Trigger.isInsert) {
for (Account newAccount:Trigger.new) {
newAccount.Account_Score_History__c = 'TESTING RECORDS 5';
}
}
Thanks,
Vishal