Sub topic 1
When Bulk API 2.0 is the right tool
Bulk API 2.0 is the Salesforce REST API for inserting, updating, upserting, deleting and querying records in volumes too large for synchronous APIs. This chapter helps you decide when to use it and when to pick something else.
Prerequisites
This chapter assumes you know:
- The basic Salesforce data model: objects, fields, record IDs and external ID fields.
- REST APIs and HTTP methods such as GET, POST, PUT and PATCH.
- How to read JSON and CSV.
- Where an OAuth access token comes from. Getting one is not covered in depth in this tutorial.
The working model: asynchronous jobs
Most Salesforce APIs are synchronous. You send a request, wait, and get the result in the response. Bulk API 2.0 is asynchronous. You create a job, upload your data, and tell Salesforce to start. You then check back later for the outcome.
Salesforce splits your data into batches internally and processes them in the background. You do not create or manage batches yourself. That is the main difference from the older Bulk API 1.0, where you built batches by hand.
Choosing between APIs
The right choice depends mostly on how many records you have and whether the caller needs an immediate answer.
| API | Best for | Processing | Typical volume |
|---|---|---|---|
| REST API (single record or composite) | Interactive apps that need an immediate result | Synchronous | One record up to a few hundred per call |
| SOAP API | Existing integrations built on the WSDL | Synchronous | Up to a few hundred per call |
| Bulk API 2.0 | Loading, updating, deleting or exporting large sets | Asynchronous | Thousands to millions of records |
| Bulk API 1.0 | Legacy integrations, XML or manual batch control | Asynchronous | Thousands to millions of records |
Check the current Salesforce documentation for exact per-call and daily limits, because they change between releases.
Signs that Bulk API 2.0 fits
Choose Bulk API 2.0 when most of these are true:
- You are moving tens of thousands of records or more.
- The data already exists as CSV, or is easy to export as CSV.
- You can wait minutes or hours for completion.
- You want per-record results, with successes and failures reported separately.
- You want Salesforce to handle batching so you do not have to.
- You need to export a large result set with a query.
Signs that another API fits better
Avoid Bulk API 2.0 when:
- A user is waiting on screen and needs the new record ID immediately. Use the REST API.
- You are changing only a handful of records. Job setup costs more than it saves.
- You need to change related records together in one all-or-nothing transaction. Bulk jobs process records in batches, and a failed record does not roll back the others.
- Your data is not CSV and you cannot convert it.
- Your integration depends on Bulk API 1.0 features such as XML or JSON payloads or manual batch control.
What you will build in this tutorial
The later chapters follow one load from start to finish. You will create an ingest job for Contact records, upload a CSV file, close the job, monitor it, and read successful, failed and unprocessed results. After that you will run an upsert with an external ID, export data with a query job, and apply the limits and performance practices that keep large loads reliable.
Exercise
A nightly process must load 2 million Account updates from a CSV file, and nobody needs the results immediately. A separate web form must create one Lead and show the new Lead ID to the user right away. Which API fits each case, and why?
Show answer
Use Bulk API 2.0 for the nightly load. The volume is large, the data is CSV, and the process can wait for asynchronous completion. Use the standard REST API for the web form. It handles single records synchronously and returns the new record ID in the response.
Exercise
Why is Bulk API 2.0 a poor choice when you need several related records saved in one all-or-nothing transaction?
Show answer
Salesforce processes bulk data in batches, and a failed record does not roll back records that succeeded. You get per-record results instead of a single transaction outcome, so it cannot guarantee that related records are saved together or not at all.