function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KS KumaarKS Kumaar 

inserting multiple records using post method in workbench

By providing following uri and by using following Request Body, we can insert a single in sObject 

uri: /services/data/v36.0/sobjects/sObject
Request Body : {
"field1" :"value1",
"field2" :"value2"
}
But, how to insert multiple records in an object using post method in workbench?
Could any one please suggest me.

Best Answer chosen by KS Kumaar
Amit Chaudhary 8Amit Chaudhary 8
NOTE your URL should be like below
/services/data/v34.0/composite/tree/Account/
Method :- Post
Request body :-
{
"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"
    }]
}
User-added image

Please let us know if this will help you

Thanks
Amit Chaudhary

 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please check below post for sample code.
1) http://amitsalesforce.blogspot.in/2016/04/rest-api-in-salesforce-execute-rest-api.html

Create Multiple Records
1) https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_composite_sobject_tree_flat.htm
Example request body newrecords.json file for creating four new accounts
{
"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"
    }]
}

Let us know if this will help you
 
KS KumaarKS Kumaar
User-added image

Hi Amit Chaudhary,
Already I tried this one. But showing error as shown in image
Amit Chaudhary 8Amit Chaudhary 8
NOTE your URL should be like below
/services/data/v34.0/composite/tree/Account/
Method :- Post
Request body :-
{
"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"
    }]
}
User-added image

Please let us know if this will help you

Thanks
Amit Chaudhary

 
This was selected as the best answer
KS KumaarKS Kumaar

Hi Amit Chaudhary,

thanks for your help.

KS KumaarKS Kumaar

Hi Amit Chaudhary,
Can you clarify few more 

can we get bulk records by using get method with out using rest sourse class?
can we update bulk records by using patch or put method with out using rest sourse class?
if it is possible please let me know with URI and Request body?