NOTE: The contents of this article apply to batch Apex jobs where the start method returns a query locator for a SOQL query that doesn't contain any inner or subqueries in it.
When a batch Apex job runs with a set batch size, the number of records processed in one batch iteration is not guaranteed to equal the configured scope size (scopeSize). As a result, the total number of batch iterations is not simply the number of records divided by the scope size. This article explains how Salesforce determines the number of execute() iterations based on the retrieve chunk size.
Records from the query locator are retrieved in chunks of a given chunk size, called retrieveChunkSize.
Retrieve Chunk Sizes
Records from the query locator are retrieved in chunks of a fixed retrieve chunk size (retrieveChunkSize). There are three available values for retrieveChunkSize — 100, 400, and 2000. Salesforce selects the smallest value that is greater than or equal to the configured scope size:
Each execute chunk (the records passed to the execute() method) has a size that depends on the chosen retrieveChunkSize, the scopeSize, and the available records in the current retrieve chunk.
Worked Example: 290 Records with Scope Size 75
Given: 290 records, scopeSize = 75, therefore retrieveChunkSize = 100. This produces 3 retrieve chunks and 6 execute chunks:
Retrieve Chunk 1 (first 100 records):
Retrieve Chunk 2 (next 100 records):
Retrieve Chunk 3 (remaining 90 records):
Total batches = 6, not ceiling(290/75) = 4. When a retrieve chunk contains the full 100 records, it is processed in two execute() calls of 75 and 25 records respectively.
000381863

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.