Sub topic 11
Batch size and Bulk API settings
This chapter assumes you have run at least one Data Loader insert or update and can read the success and error files. It covers the settings that control how Data Loader sends rows to Salesforce, and how to choose them.
What a batch is
Data Loader does not send a file to Salesforce in one piece. It splits the CSV into batches. Each batch is a group of rows sent in one request, and Salesforce processes each batch as its own unit. If one batch fails, other batches can still succeed.
Two APIs carry these requests:
- SOAP API (the default) sends batches synchronously. Data Loader waits for each response. The default batch size is 200 rows, and the maximum is 200.
- Bulk API sends batches asynchronously. Salesforce queues them and processes them in the background. Batches can hold up to 10,000 rows. Bulk API 2.0 does the batching for you.
Where to change the settings
Open Settings in Data Loader. The options that matter here are:
| Setting | Effect |
|---|---|
| Batch Size | Number of rows per batch. |
| Use Bulk API | Switches from SOAP API to Bulk API. |
| Enable serial mode for Bulk API | Processes batches one at a time instead of in parallel. |
| Upload Bulk API Batch as Zip File | Sends attachments or binary content in a zip. |
| Timeout Size | How long Data Loader waits for a response. |
The exact labels and defaults vary by Data Loader version, so check your installed version.
Choosing a batch size
Pick the size based on the data volume and on what runs when records save.
- Under about 50,000 rows: SOAP API with the default size is usually fine.
- Hundreds of thousands or millions of rows: use Bulk API. It is built for volume and uses fewer API calls.
- Heavy automation on the object: triggers, flows, and complex validation rules run for every row. Large batches can hit governor limits, which are per-transaction caps on CPU time, queries, and DML statements. Lower the batch size, for example to 50 or 20, if you see limit errors.
Each batch is a transaction. With SOAP API, an error in one row usually fails only that row, but a governor limit error can fail the whole batch. Smaller batches limit how many rows one such failure affects.
Parallel and serial mode
Bulk API runs batches in parallel by default. That is faster, but concurrent batches can contend for the same locks. If many rows point at the same parent record, or the same account, parallel batches can fail with UNABLE_TO_LOCK_ROW.
Enable serial mode to avoid this. Batches then run one after another. The load is slower, but lock errors mostly disappear.
Limits to keep in mind
Every API request counts against your org's daily allocation. SOAP API with 200-row batches uses one call per batch, so a 1,000,000-row load is about 5,000 calls. Bulk API counts batches, not rows, so it uses far fewer. Check your org's limits under Company Information or in the API usage reports before a large load.
Also note that Bulk API does not report row errors immediately. You see them in the error file after the job finishes. For a large load, start with a small test file of a few hundred rows to confirm that mapping and validation behave as expected.
Worked example
You need to update 300,000 Contacts. The Contact object has several flows and a trigger.
- Test 500 rows in a sandbox with Bulk API on and batch size 200.
- The error file shows
UNABLE_TO_LOCK_ROWfor rows sharing an Account. - Turn on serial mode and rerun the test. The lock errors stop.
- Run the full load in the sandbox, review the error file, then repeat in production.
Exercise
A Bulk API load fails some rows with UNABLETOLOCK_ROW. Many of the rows share the same parent Account. Name two ways to reduce these errors.
Show answer
Enable serial mode so batches run one at a time, and sort the CSV by parent Account ID so rows with the same parent fall in the same batch. Lowering the batch size can also help.
Exercise
Why might you lower the batch size when loading into an object that has several flows and triggers?
Show answer
Automation runs for every row in a batch inside one transaction. A large batch can exceed governor limits, such as CPU time, and fail. Smaller batches reduce the number of rows affected by one failure.