Activity Forums Salesforce® Discussions What is the meaning for 10 in the syntax "Database.executeBatch(batchObject,10)" in Salesforce? Is that the total batch size or etc.,?

  • What is the meaning for 10 in the syntax "Database.executeBatch(batchObject,10)" in Salesforce? Is that the total batch size or etc.,?

    Posted by Udit on January 20, 2020 at 3:35 pm

    What is the meaning for 10 in the syntax "Database.executeBatch(batchObject,10)"? Is that the total batch size or etc.,?

    • This discussion was modified 4 years, 10 months ago by  Udit.
    • This discussion was modified 4 years, 10 months ago by  Udit.
    • This discussion was modified 4 years, 10 months ago by  Udit.
    MOHIT replied 4 years, 10 months ago 2 Members · 1 Reply
  • 1 Reply
  • MOHIT

    Member
    January 20, 2020 at 7:53 pm

    global void execute(SchedulableContext cc) {
    BatchApexClass batchObject = new BatchApexClass();
    Database.executeBatch(batchObject,10) ;// I think you are asking about this 10.}

    Basically, Database's executeBatch method has two overloads

    One which takes only one parameter i.e. instance of the batch class and does not take scope as parameter and processes the records with default batch size of 200.
    Other which takes two parameters, first the instance of the batch class and second the scope variable i.e. an integer which specifies the number of records to be passed into the execute method for batch processing.
    So in above example, its the second overload which will pass 10 records at a time to execute method of batch class for processing. If you have 100 records in all to be processed and if you have set your batch size as 10, your records would be split in 100/10 i.e. 10 batches i.e. execute method will run 10 times.

    The default size of the scope if not specified is 200 and the maximum value it can have is 2000.

    Excerpt from Salesforce Database class documentation

    The value for scope must be greater than 0.

    If the start method of the batch class returns a Database.QueryLocator, the scope parameter of Database.executeBatch can have a maximum value of 2,000. If set to a higher value, Salesforce chunks the records returned by the QueryLocator into smaller batches of up to 200 records. If the start method of the batch class returns an iterable, the scope parameter value has no upper limit; however, if you use a very high number, you could run into other limits.

    Apex governor limits are reset for each execution of execute.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos