How does one handle individual record errors in a Batch Process?
Tried the following example below, but once I iterate through wlist after the batch has completed (checking the job status through an apex:actionPoller), the wlist contains no errors, even though several have occurred.
//Calling Class
MyBatchClass job = new MyBatchClass(wlist);
Id jobId = Database.executeBatch(job);
//iterate through wlist to look for record erros
//Batch class
global class MyBatchClass implements Database.Batchable<SObject>,Database.Stateful{
global List<MyWrapper> wlist {get;set;}
global Integer currentIndex {get;set;}
public MyBatchClass(List<MyWrapper> wlist){
this.currentIndex = 0;
this.wlist = wlist;
}
global Iterable<sObject> start(Database.BatchableContext bc){
List<MyObject__c> olist = new List<MyObject__c>();
for(MyWrapper w : rewardPoints){
olist.add(w.obj);
}
return olist;
}
global void execute(Database.BatchableContext bc, sObject [] objects){
for(Database.SaveResult sr : Database.insert(objects,false)){
if(!sr.success){
wlist.get(currentIndex).errorMessage = sr.getErrors().get(0);
}
currentIndex++;
}
}
global void finish(Database.BatchableContext bc){}
}