2

Note: This is not a duplicate of the other similar questions. We checked them before. So please don't close this as a duplicate!

When calling this batch class in a production org:

global class MyBatch implements Database.Batchable<SObject>{

    global Set<Id> contactIds;
    global String query;


    global MyBatch (Set<Id> contactIds) {
        this.contactIds = contactIds;
        this.query = 'SELECT Id from Package_Contact__c WHERE ID IN :contactIds';
    }


    global Database.QueryLocator start(Database.BatchableContext ctx) {
        return Database.getQueryLocator(query);
    }


    global void execute(Database.BatchableContext ctx, List<SObject> scope) {
        System.debug(scope);
        try {
            delete scope;
        }
        catch(Exception e) {

        }
    }


    global void finish(Database.BatchableContext ctx) {

    }
}

from this scheduled class directly via the DevConsole

global class MyScheduled implements Schedulable {

    ...


    global void execute(SchedulableContext ctx) {
        Database.executeBatch(new MyBatch(fourThousandIDS));
    }

    ...
}

everything runs fine.

But when we call this class scheduled each night it fails with

LimitException: Batchable instance is too big

This must be a server thing or a platform bug newly introduced.

  • 1
    Can you add exactly how you are invoking it in the Dev Console? Is it by "new MyScheduled(someListOfIds).execute(null);"? – Phil W Jan 29 at 12:24
  • 1
    @PhilW Yes we ran with new MyScheduled().execute(null); – dennisjsk Jan 29 at 12:32
  • 4
    So how is the list of IDs "fourThousandIDS" initialized? Could this be the source of the issue? – Phil W Jan 29 at 12:33
  • 3
    What I wonder about is whether the list of IDs is actually generated the same in both cases. For example, perhaps you have sharing rules that limit the list length in the dev console, but the usage in production actually gets a different list that is longer? – Phil W Jan 29 at 12:44
  • 2
    OK, if you are 100% sure. It seems like there is too much state held in your Batchable and that the instantiation context causes this to vary significantly. Do you hold any other state than the list of IDs and the query? – Phil W Jan 29 at 12:59

Your Answer

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

Browse other questions tagged or ask your own question.