i need to insert multiple records from one org to another org using rest API(bulk) am unable to insert multiple records ..as of now am able to insert single record successfully.can you please tell how to do this ..

  • why don't you use 'Salesforce to salesforce'? – Ganesh Bhosle Dec 2 '13 at 5:54
  • @ hi ganesh ,,we need to achieve this functionality using REST API only – Vineeth Dec 2 '13 at 5:55
  • What's wrong making multiple REST Calls, why can't you loop through records to be inserted?..how large is that data? – Ganesh Bhosle Dec 2 '13 at 6:02
  • i Have 200 records to be insert in one single bulk API call – Vineeth Dec 2 '13 at 6:04
  • Use Apex Job Scheduling: Make 10 Callouts per job, schedule 20 such jobs. This isn't an elegant way of doing it, but it will work. – Ganesh Bhosle Dec 2 '13 at 6:11

Take a look at the Salesforce Bulk API described here.

When to Use REST API

REST API provides a powerful, convenient, and simple REST-based Web services interface for interacting with Salesforce. Its advantages include ease of integration and development, and it’s an excellent choice of technology for use with mobile applications and Web projects. However, if you have a large number of records to process, you may wish to useBulk APIBulk API, which is based on REST principles and optimized for large sets of data.

When to Use Bulk API

Bulk API is based on REST principles and is optimized for loading or deleting large sets of data. You can use it to query, insert, update, upsert, or delete a large number of records asynchronously by submitting batches which are processed in the background by Salesforce.

How Bulk API Works

You process a set of records by creating a job that contains one or more batches. The job specifies which object is being processed and what type of action is being used (query, insert, upsert, update, or delete). A batch is a set of records sent to the server in an HTTP POST request. Each batch is processed independently by the server, not necessarily in the order it is received. Batches may be processed in parallel. It's up to the client to decide how to divide the entire data set into a suitable number of batches.

A job is represented by the JobInfo resource. This resource is used to create a new job, get status for an existing job, and change status for a job. A batch is created by submitting a CSV or XML representation of a set of records and any references to binary attachments in an HTTP POST request. Once created, the status of a batch is represented by a BatchInfo resource. When a batch is complete, the result for each record is available in a result set resource.

Processing data typically consists of the following steps:

  1. Create a new job that specifies the object and action.
    1. Send data to the server in a number of batches.
    2. Once all data has been submitted, close the job. Once closed, no more batches can be sent as part of the job.
    3. Check status of all batches at a reasonable interval. Each status check returns the state of each batch.
    4. When all batches have either completed or failed, retrieve the result for each batch.
    5. Match the result sets with the original data set to determine which records failed and succeeded, and take appropriate action.
  • Are you wanting to call this API from Apex? Its theoretically possible, but I am not aware of any examples off hand. I assume you have the regular REST API working and since the Bulk API is also REST based, you should be able to adapt your code having studied the guide linked above. – Andrew Fawcett Dec 2 '13 at 10:43
  • yes Andrew ,,want to call api from apex .thanks for your guidelines – Vineeth Dec 3 '13 at 6:21
  • That would be an interesting project to shown an Apex example of this API.... i'll add to my blog list, but feel free to share your success as well sometime! :) – Andrew Fawcett Dec 3 '13 at 10:15
  • Sure Andrew ... – Vineeth Dec 3 '13 at 10:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.