I get the error First error: Invalid conversion from runtime type CustomIterable to System.Iterable when trying to use a customer iterable in a batch job.
My custom iterable class:
global class CustomIterable implements Iterator<SObject>{
List<SObject> sobjs {get; set;}
Integer i {get; set;}
public CustomIterable(){
sobjs = new List<SObject>();
List<Account> accs = [SELECT Id, Name, OFAC_Last_Check_Date__c,OFAC_Passed__c FROM Account];
for( Account acc : accs ) {
sobjs.add(acc);
}
List<Contact> cons = [SELECT Id, FirstName, LastName, OFAC_Last_Check_Date__c,OFAC_Passed__c FROM Contact];
for( Contact con : cons ) {
sobjs.add(con);
}
i = 0;
}
global boolean hasNext(){
if(i >= sobjs.size())
return false;
else
return true;
}
global SObject next(){
if(i == 8){ i++; return null;}
i=i+1;
return sobjs[i-1];
}
}
This is how I call the above code:
global Iterable<SObject> start(Database.batchableContext info){
//Iterable<SObject> myIter = (Iterable<SObject>)new CustomIterable();
return new CustomIterable();
}
I followed this example from the documentation. I am trying use two objects in the batch job, hence the custom iterable.
Thanks!