10

We can use the Force.com REST API to perform DML operations. I want to know if there is a way that we can insert/update more than 1 record using a single REST API call.

1

3 Answers 3

4

Found a post by @superfell - "You can't insert multiple rows in a single call in the rest api, you need to use the bulk api." https://stackoverflow.com/questions/5898590/rest-multiple-insert

1
  • It's been almost three years since the answer you mentioned was posted. Is it still true that it isn't supported? Commented Apr 2, 2014 at 14:47
9

Looks like there is an option coming in Summer `15

In Summer '15 there are new and changed resources available through the REST API.

Batch

vXX.X/composite/batch
The Batch resource lets you execute a sequence of independent subrequests. For example, you can update the name on an account and get the account’s field values in a single request.

{
"batchRequests" : [
    {
    "method" : "PATCH",
    "url" : "v34.0/sobjects/account/001D000000K0fXOIAZ",
    "richInput" : {"Name" : "NewName"}
    },{
    "method" : "GET",
    "url" : "v34.0/sobjects/account/001D000000K0fXOIAZ"
    }]
} 

The response contains the status codes of each subresponse and the responses themselves.

{   
"hasErrors" : false,
"results" : [
    {     
    "statusCode" : 204,
    "result" : null
    },{
    "statusCode" : 200,
    "result" : { Account attributes }
    }] 
}

Plus there is a pilot for the SObject Tree resource that:

lets you create multiple sObject trees that share a root record type. An sObject tree is a collection of nested, parent-child records with a single root record.

Knowledge Article Number: 000214070 - Summer `15 - REST API Updates

1

Surely yes you can .

All you need to do is refer the below code to get started,I assume its POST call and you are familiar with @HTTP POST annotations

Here is the sample code

List<Account> lstacc=new List<Account>();

    //Extracting the data from the JSON HTTP request object sent from iPad
    RestRequest req = RestContext.request;
    RestResponse res=RestContext.response;
    Blob body=req.requestBody;
    String jsonToParse=body.toString(); 
    lstacc=(List<Account>)JSON.deserialize(jsonToParse, List<Account>.class);
    update lstacc;

Also the following link from apex guide will help you

http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_json.htm?SearchType=Stem

There is wonderful blog from Abhinav Gupta force.com MVP on this that may help you as well

http://www.tgerm.com/2011/10/winter12-jsonparser-serialize.html

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .