I am trying to chunk the results of a query of mine, but I am noticing the batches stop after 50,000 records (25 batches of 2000 records). I read iterable has a limit of 50,000 but I thought that was 50,000 records per batch.

What are my options for being able to query and process all of my case records when recordtype 000 has over 50,000 records and record type 111 has over 50,000 records?

Execute Anonymous:

Database.executeBatch(new batchClassExample(), 2000);

Batch Class:

global class batchClassExample implements Database.Batchable < Case > {

    List < string > exampleRecordTypeIds = new List < string > ();

    global batchClassExample() {
        string exampleRecordTypeIdString = '000XXX000XXX, 111XXX111XXX';
        exampleRecordTypeIdString = exampleRecordTypeIdString.deleteWhitespace();
        exampleRecordTypeIds = exampleRecordTypeIdString.split(',');

    global Iterable < Case > start(Database.BatchableContext BC) {
        Integer count = Limits.getLimitQueryRows() - Limits.getQueryRows();
        return [select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds LIMIT: count

    global void execute(Database.BatchableContext BC,
        List < Case > scope) {

        for (integer s = 0; s < scope.size(); s++) {



    global void finish(Database.BatchableContext BC) {


Your start method is limited to 50,000 SOQL rows, except for your Database.QueryLocator, if you choose to use one. To get past this limit, use a Database.QueryLocator:

    return (Iterable<Case>)Database.getQueryLocator([
      select Id, Owner.Id from case where RecordType.Id = :exampleRecordTypeIds

A batch can process up to 50 million records. Based on documentation , I think you may want to change your code in the following ways:

  1. Create a global string variable, call it "queryString" for example - which holds the query for both recordtypes (I.E 'Where RecordTypeId IN: recordTypeIds')

  2. Change the start() method to return type DataBase.queryLocator, and within the start method call Database.queryLocator(queryString).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.