Batches under Bulk API jobs salesforce

apexbulk-apibulk-api-v2

In Salesforce Bulk API, let's say I want to insert 1K Opportunity records. So, I created a job, and added all 1K records to the one single request body and all these records got generated successfully.

But just wondering on few things:

  1. After inserting , I went to Setup > Bulk Data Load Jobs, to check the status, I observed that it says number of Batches processed is 1. Why does it shows 1, it should process 200 records in single batch, correct? So, shouldn't is show 1000/200 = 5 batches?

enter image description here

  1. If I can insert all the records in 1 single batch then in what scenario should we create another batch under same jobId. I want to understand a use case wherein we have to create multiple batches under same job.

  2. What is the batch size in case of Bulk API and how can we modify it?

Best Answer

The notion of a batch in the Bulk API is rather confusing. A bulk batch is the unit that the Bulk API executes in parallel (assuming that parallel mode is turned on). It is not identical with a transaction of 200 records - in the Bulk API, you cannot control how many records are processed in a single transaction. The behavior is also different in the Bulk API 1.0 and 2.0

Bulk API 1.0

In Bulk API 1.0, you create batches under each job. Again, assuming that parallel mode is turned on, those batches will be divided by the Bulk API into 200-record chunks and executed in parallel. You are responsible for creating batches that meet the limits specified by the Bulk API:

  • 10 minute processing time for the whole batch
  • No more than 10 MB per batch
  • No more than 10,000 records per batch

Bulk API 2.0

In the Bulk API 2.0, you don't create batches yourself. Instead, the Bulk API automatically creates batches after you complete an ingest operation.