[SalesForce] How to process more than 25 batches of 2000 records

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++) {
            system.debug(scope[s]);

        }

    }

    global void finish(Database.BatchableContext BC) {

    }
}

Best Answer

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
      ]);