+ Start a Discussion
XactiumBenXactiumBen 

Help with Batch Apex - QueryLocator returning 6 records but only executing 1 record

I have started looking at Batch Apex mainly to solve an issue with governor limits but can't seem to get it working.  Here is my code (queries and object names changed):

 

global with sharing class BatchUpdate implements Database.Batchable<SObject> { private final Set<Id> ids; global BatchUpdate(Set<Id> ids) { this.ids = ids; } global Database.QueryLocator start(Database.BatchableContext bc) { return Database.getQueryLocator([Select -lots of fields- Where Lookup__c in :this.ids]); } global void execute(Database.BatchableContext BC, List<SObject> records) { List<Object__c> updateRecords = new List<Object__c>(); for (SObject r : records) { Object__c rs = (Object__c)r; system.debug(rs.id); updateRecords.add(rs); } if (updateRecords.size() > 0) HelperClass.updateRecordsFromList(updateRecords); } global void finish(Database.BatchableContext BC){} }

 

 

I've looked at my debug logs and found that the start method returns 6 records (as it should) but the execute method only processes 1 record.  Can anyone see anything that I've done wrong?

XactiumBenXactiumBen
Help anyone?  I'm unsure if this is a bug or if I'm just not doing things quite right.
metaforcemetaforce

I just hope this is not the last record out of the 6 records getting returned, or is it?

 

Instead of writing like this:

 

Object__c rs = (Object__c)r;

 

try this:

 

Object__c rs = new Object__c();

rs = (Object__c)r;

updateRecords.add(rs);

 

XactiumBenXactiumBen

I retested this again recently and it seemed to have no troubles this time.

 

Thanks for your help anyway.