Concept 4 of 8Data at scale

Bulk API 2.0

Asynchronous loading and querying of large data volumes: ingest and query jobs, CSV payloads, upserts with external IDs, locking, limits, and how it compares with Bulk API 1.0.

Your confidence:Not rated

Simple explanation

Bulk API 2.0 processes large data sets asynchronously. You create a job, upload CSV data, close the job, and Salesforce splits the data into internal batches and processes them in parallel.

Ingest jobs (insert, update, upsert, delete, hard delete):

  1. POST /jobs/ingest with object, operation, (for upsert) externalIdFieldName.
  2. PUT /jobs/ingest/{id}/batches with CSV data.
  3. PATCH /jobs/ingest/{id} with state: UploadComplete.
  4. Poll the job, then download successfulResults, failedResults and unprocessedrecords.

Query jobs: POST /jobs/query with a SOQL query; download results in pages (with a locator) when the job completes. queryAll includes deleted and archived records.

Compared with Bulk API 1.0: 2.0 manages batching for you, has simpler limits and supports query result paging. 1.0 lets you control batches and serial vs parallel mode, and is still used by some tools.

Design tips

  • Upsert with external IDs so reruns are safe and parents can be referenced by external ID (Account.ERP_Id__c in a contact CSV).
  • Sort data by parent (for example contacts by AccountId) to reduce record lock contention; if locks persist, reduce parallelism.
  • Turn off or bypass non-essential automation during big loads, and defer sharing calculations where supported.
  • Load in dependency order: users and accounts before contacts and opportunities.

Real-world analogy

Bulk API is a container ship: slow to load and unload, but it moves an enormous amount at once. REST API calls are courier vans, fast for a few parcels and absurd for a million.

Worked example

Upserting contacts by an external ID, referencing the parent account by its external ID:

POST /services/data/v66.0/jobs/ingest
Content-Type: application/json

{ "object": "Contact", "operation": "upsert", "externalIdFieldName": "Legacy_Id__c",
  "contentType": "CSV", "lineEnding": "LF" }
PUT /services/data/v66.0/jobs/ingest/750XXXXXXXXXXXX/batches
Content-Type: text/csv

Legacy_Id__c,FirstName,LastName,Email,Account.ERP_Id__c
CT-0001,Amara,Okafor,amara.okafor@example.com,C-48213
CT-0002,Jonas,Lindqvist,jonas.lindqvist@example.com,C-48213
PATCH /services/data/v66.0/jobs/ingest/750XXXXXXXXXXXX
Content-Type: application/json

{ "state": "UploadComplete" }

Then poll GET /jobs/ingest/750XXXXXXXXXXXX until JobComplete and download failedResults/ for errors.

Diagram

Rendering diagram…

Key points

  • Jobs (ingest or query), CSV, asynchronous processing, results files per outcome.
  • Upsert with external IDs, parents referenced by external ID.
  • Sort by parent and manage parallelism to avoid record locks.
  • Bypass non-essential automation and plan load order.
  • 2.0 manages batching; 1.0 offers serial mode and manual batches.
  • Daily limits on records and batches apply βš‘ verify current values.

Limits and gotchas

  • Record lock errors (UNABLE_TO_LOCK_ROW) come from parallel batches touching the same parent; sort or serialise.
  • Triggers and flows run for Bulk API loads, in chunks of 200, and can make loads slow or fail.
  • Hard delete bypasses the recycle bin and needs a specific permission. Use with care.
  • Query jobs over huge tables need selective filters; PK chunking (Bulk 1.0) or the 2.0 automatic handling helps for full extracts βš‘ verify.
  • Sharing recalculation after large ownership changes can take hours; schedule it.

🎀 How to say this in an interview

"Load 20 million records" questions test whether you mention external IDs, load order, locking, automation bypass, sharing deferral, sandbox rehearsal and reconciliation. Bulk API itself is the easy part.

Common follow-ups

How do you reconcile after a large load?

Compare record counts and key totals per object between source and Salesforce, check the failed-results files, spot-check samples, and rerun failures by external ID after fixing the data.

Why sort contacts by AccountId before loading?

Parallel batches that insert children of the same account compete for a lock on that account. Grouping children of the same parent into the same batch reduces lock contention.