Newer Version Available
Step 3: Adding a Batch to the Job
After creating the job, you're now ready to create a batch of contact records. You send data in batches in separate HTTP POST requests. The URI for each request is similar to the one you used when creating the job, but you append jobId/batch to the URI.
Format the data as either CSV or XML if you're not including binary attachments. For information about binary attachments, see Loading Binary Attachments. For information about batch size limitations, see Batch size and limits.
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'll keep it very simple with just a few records.
To add a batch to a job:
- Create a CSV file named data.csv with the
following 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."Note that 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 the following cURL command:
curl https://instance.salesforce.com/services/async/34.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 the following:
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</batchInfo>Salesforce does not 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.