Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
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.
1FirstName,LastName,Department,Birthdate,Description 2Tom,Jones,Marketing,1940-06-07Z,"Self-described as ""the top"" branding guru on the West Coast" 3Ian,Dury,R&D,,"World-renowned expert in fuzzy logic design. 4Influential 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/67.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.
1<?xml version="1.0" encoding="UTF-8"?> 2<batchInfo 3 xmlns="http://www.force.com/2009/06/asyncapi/dataload"> 4 <id>751x00000000079AAA</id> 5 <jobId>750x0000000005LAAQ</jobId> 6 <state>Queued</state> 7 <createdDate>2009-09-01T17:44:45.000Z</createdDate> 8 <systemModstamp>2009-09-01T17:44:45.000Z</systemModstamp> 9 <numberRecordsProcessed>0</numberRecordsProcessed> 10 <numberRecordsFailed>0</numberRecordsFailed> 11 <totalProcessingTime>0</totalProcessingTime> 12 <apiActiveProcessingTime>0</apiActiveProcessingTime> 13 <apexProcessingTime>0</apexProcessingTime> 14</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.