[SalesForce] Create/update multiple records using REST (Not Bulk API)

I have used REST in the past for creating/updating single record and used Bulk API to create records in bulk too. But there seems to be new way to creating multiple records using REST. Here is the article – https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_composite_sobject_tree_flat.htm

Can someone post few help articles on how to get started? I have not used curl in the past, is there way to test this using PostMaster or WorkBench?

Edit

Let me make it simple. Suppose I have below REST resource in Salesforce, how can I call it to pass multiple contact records?

@RestResource(urlMapping='/insertcontact/*')

global with sharing class Mycontacts{

@HttpPost
global static List doPost(List lstcnts){
insert lstcnts;
return lstcnts;
}

}

Best Answer

You can definitely use workbench to execute these

Use the below for the request

/services/data/v34.0/composite/tree/Account

and in the body use the below JSON

{
"records" :[{
"attributes" : {"type" : "Account", "referenceId" : "ref1"},
"name" : "SampleAccount1",
"phone" : "1111111111",
"website" : "www.salesforce1.com",
"numberOfEmployees" : "100",
"industry" : "Banking"   
},{
"attributes" : {"type" : "Account", "referenceId" : "ref2"},
"name" : "SampleAccount2",
"phone" : "2222222222",
"website" : "www.salesforce2.com",
"numberOfEmployees" : "250",
"industry" : "Banking"
},{
"attributes" : {"type" : "Account", "referenceId" : "ref3"},
"name" : "SampleAccount3",
"phone" : "3333333333",
"website" : "www.salesforce3.com",
"numberOfEmployees" : "52000",
"industry" : "Banking"
},{
 "attributes" : {"type" : "Account", "referenceId" : "ref4"},
 "name" : "SampleAccount4",
 "phone" : "4444444444",
 "website" : "www.salesforce4.com",
 "numberOfEmployees" : "2500",
 "industry" : "Banking"
  }]
}

You should see the response in workbench

Alternatively you can use POSTMAN to experiment with this API .

You will need to create a connected app in salesforce and use oauth 2.0 to get access token for subsequent calls

use the below link for reference

Related Topic