Sub topic 14
Limits and How Salesforce Batches Your Data
This chapter assumes you can already create an ingest job, upload CSV data, set UploadComplete, and poll job state. Here you will learn what limits apply to a Bulk API 2.0 load and what Salesforce does with your file after you close the job. You will also learn how to size your own uploads.
Who does the batching
In the older Bulk API (1.0) you split data into batches yourself and submitted each one. Bulk API 2.0 removes that step. You upload one CSV, or a few pieces of one, to a job. After you set UploadComplete, Salesforce divides the data into internal batches and processes them.
The practical effects:
- You do not choose the batch size and cannot tune it.
- You do not get per-batch IDs. Results are reported per job.
- Processing order is not guaranteed. Do not rely on rows being processed in file order.
- Salesforce may retry internal batches that fail with transient problems such as row lock errors. The job info reports this in its
retriesfield.
The limits that matter
Salesforce changes these numbers between releases. Treat the table as a working model, and confirm the values in the current Bulk API 2.0 limits documentation before you design a production load.
| Limit | Typical value | Why it matters |
|---|---|---|
| Data size per ingest job | 150 MB | Larger loads need several jobs. |
| Records per rolling 24 hours | 150,000,000 | An org-wide cap that all of your jobs share. |
| Internal batches per rolling 24 hours | 15,000, shared with Bulk API 1.0 | Each internal batch counts, even when Salesforce created it. |
| Records per internal batch | Up to 10,000 | Fixed by Salesforce. It sets how many batches a job consumes. |
| Record size | About 400,000 characters across all fields | Wide rows with long text fields can hit this. |
| Retention of job data and results | 7 days | Download results before they expire. |
The first three limits interact, so check them against each other. A 150 MB job of short Contact rows might hold 1.5 million records. That is 150 internal batches, about 1% of the daily batch allowance. A single 150 MB job cannot exhaust the daily batch limit on its own. Many smaller jobs, retries and other Bulk API clients running at the same time can.
Job size and the 150 MB ceiling
The size limit applies to the data you upload. Salesforce documents it as a size after encoding, so for safety keep each file well below 150 MB. About 100 MB leaves a margin. If your source file is larger, split it into several files and create one job per file. You can also upload several pieces to one job, as long as the total stays within the limit.
Every piece needs the header row if you create a separate job for it. Never split a CSV in the middle of a quoted field. A newline inside quotes is part of the value, so a naive line-based splitter corrupts rows. This script splits on record boundaries using Python's csv module and repeats the header in each part:
import csv
import io
import sys
MAX_BYTES = 100 * 1024 * 1024
def encode_row(row):
buf = io.StringIO()
csv.writer(buf, lineterminator="\n").writerow(row)
return buf.getvalue().encode("utf-8")
def split_csv(path, prefix, max_bytes=MAX_BYTES):
parts = []
out = None
size = 0
with open(path, newline="", encoding="utf-8") as src:
reader = csv.reader(src)
header = encode_row(next(reader))
for row in reader:
line = encode_row(row)
if out is None or size + len(line) > max_bytes:
if out is not None:
out.close()
name = f"{prefix}_{len(parts) + 1:03d}.csv"
parts.append(name)
out = open(name, "wb")
out.write(header)
size = len(header)
out.write(line)
size += len(line)
if out is not None:
out.close()
return parts
if __name__ == "__main__":
for name in split_csv(sys.argv[1], sys.argv[2]):
print(name)Run it as python split_csv.py contacts_all.csv contacts. It writes contacts_001.csv, contacts_002.csv and so on. The script always writes LF line endings, so create each job with "lineEnding": "LF".
Record and field limits
A row can fail even when the file is small. Common causes:
- A text field value is longer than the field's defined length.
- The combined length of all fields in a row exceeds the record limit.
- A single CSV cell contains more characters than the platform allows.
These failures are per record. The job finishes, the row appears in failedResults, and its sf__Error column names the problem. A file-level problem, such as a malformed header or an unknown field name, can fail the whole job.
Reading the job counters
The job info response tells you how much of your allowance a job used. These fields are the useful ones for capacity planning:
| Field | Meaning |
|---|---|
| `numberRecordsProcessed` | Rows Salesforce has attempted so far. |
| `numberRecordsFailed` | Rows that failed. |
| `retries` | Number of internal retries. A high value suggests contention. |
| `totalProcessingTime` | Total processing time in milliseconds, including retries. |
| `apiActiveProcessingTime` | Time spent in the API layer. |
| `apexProcessingTime` | Time spent in Apex triggers and flows. |
Compare apexProcessingTime with totalProcessingTime. If Apex accounts for most of the time, the bottleneck is your triggers, flows or validation logic, not the API. Splitting the file differently will not help in that case.
Common errors
- The upload fails because the data is too large. The request exceeded the per-job size limit. Split the file and create more jobs.
- A job is rejected for exceeding a daily allowance. You have used the record or batch allowance for the rolling 24 hours. The window is rolling, not midnight, so capacity returns gradually. Check the org's limits before rerunning a large load.
- Most rows fail with
UNABLE_TO_LOCK_ROW. Parallel internal batches are updating the same parent or related records. The chapter on performance practices covers ordering your data to avoid this. - Results are missing the next day. Results expire after 7 days, but you may also have deleted the job. Download
successfulResults,failedResultsandunprocessedrecordsas soon as the job finishes. - Counts differ from your file.
numberRecordsProcessedcan lag while the job isInProgress. Only compare totals after a terminal state.
Planning a large load
- Count the records and measure the CSV size.
- If the file is over about 100 MB, split it on record boundaries.
- Calculate internal batches: records divided by 10,000, rounded up, summed over all files.
- Compare the total with the records and batches you have left in the rolling 24 hours.
- Run the jobs one after another, or a few at a time if they touch unrelated data.
- After each job, record
retriesand the processing time fields so you can tune the next run.
Exercise
You must load 4,200,000 Contact records. The CSV is 320 MB. How many job files do you need at a safe size of about 100 MB each, and about how many internal batches will the whole load use?
Show answer
At least 4 files (320 MB divided by 100 MB is 3.2, rounded up to 4), each with the header row and split on record boundaries. Internal batches are 4,200,000 divided by 10,000 = 420 in total, which is small against a 15,000 daily allowance. The record count is also well below the 150,000,000 daily record limit.
Exercise
A job finishes in state JobComplete, but the job info shows a large retries value and many failed rows with UNABLETOLOCK_ROW. Is splitting the file into smaller jobs the right fix?
Show answer
Usually not. The errors come from parallel batches locking the same related records, such as many Contacts under the same Account. Smaller jobs run at the same time would make this worse. Sort the data so rows that share a parent are together, or run the jobs one after another, then resubmit the failed rows.