Step 3: Add a Batch to the Job
Format the data as CSV, XML, or JSON if you’re not including binary attachments. For information about binary attachments, see Load Binary Attachments. For information about batch size limitations, see Bulk API and Bulk API 2.0 Limits and Allocations.
This example shows CSV as this is the recommended format. It's your responsibility to divide up your data set in batches that fit within the limits. In this example, we keep it very simple with just a few records.
To add a batch to a job:
- Create a CSV file named data.csv with these two
records.
FirstName,LastName,Department,Birthdate,Description Tom,Jones,Marketing,1940-06-07Z,"Self-described as ""the top"" branding guru on the West Coast" Ian,Dury,R&D,,"World-renowned expert in fuzzy logic design. Influential in technology purchases."
The value for the Description field in the last row spans multiple lines, so it’s wrapped in double quotes.
- Using a command-line window, execute this cURL command.
curl https://instance.salesforce.com/services/async/63.0/job/jobId/batch -H "X-SFDC-Session: sessionId" -H "Content-Type: text/csv; charset=UTF-8" --data-binary @data.csv
instance is the portion of the <serverUrl> element and sessionId is the <sessionId> element that you noted in the login response. jobId is the job ID that was returned when you created the job.
Salesforce returns an XML response with data such as this.
<?xml version="1.0" encoding="UTF-8"?> <batchInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"> <id>751x00000000079AAA</id> <jobId>750x0000000005LAAQ</jobId> <state>Queued</state> <createdDate>2009-09-01T17:44:45.000Z</createdDate> <systemModstamp>2009-09-01T17:44:45.000Z</systemModstamp> <numberRecordsProcessed>0</numberRecordsProcessed> <numberRecordsFailed>0</numberRecordsFailed> <totalProcessingTime>0</totalProcessingTime> <apiActiveProcessingTime>0</apiActiveProcessingTime> <apexProcessingTime>0</apexProcessingTime> </batchInfo>
Salesforce doesn’t parse the CSV content or otherwise validate the batch until later. The response only acknowledges that the batch was received.
- Note the value of the batch ID returned in the <id> element. You can use this batch ID later to check the status of the batch.