function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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(; 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?

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

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;




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


Thanks for your help anyway.