0

As per the documentation i understood that we can create account in the following way.

Example for creating a new Account

curl https://na1.salesforce.com/services/data/v20.0/sobjects/Account/ -H "Authorization: Bearer token -H "Content-Type: application/json" -d "@newaccount.json"

Example request body newaccount.json file for creating a new Account

{
    "Name" : "Express Logistics and Transport"
}

Example response body after successfully creating a new Account

{
    "id" : "001D000000IqhSLIAZ",
    "errors" : [ ],
    "success" : true
}

Is there a way to create multiple accounts in one shot and if it is possible what could be the JSON structure? Please suggest.

2 Answers 2

1

Right now SFDC standards REST API does not support bulk insert. So you have two options.

1) Use BULK API ( https://www.salesforce.com/us/developer/docs/api_asynch/)

2) Create your custom API that accept list of accounts. Here is example of how to do it. Check Mohits's answer. Is it possible to pass sObjects to the REST api

2
  • 1
    or, if willing to abandon REST, use SOAP API Commented Dec 17, 2014 at 3:00
  • Yes, SOAP makes more sense for this requirement. Commented Dec 17, 2014 at 4:52
0
  1. Use Composite API
  2. POST Composite SObject Tree
  3. Endpoint:

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

  1. Body Structure:

{ "records" :[{ "attributes" : {"type" : "Account", "referenceId" : "ref1"}, "name" : "SampleAccount", "phone" : "1234567890", "website" : "www.salesforce.com", "numberOfEmployees" : "100", "industry" : "Banking", "Contacts" : { "records" : [{ "attributes" : {"type" : "Contact", "referenceId" : "ref2"}, "lastname" : "Smith", "title" : "President", "email" : "[email protected]" },{
"attributes" : {"type" : "Contact", "referenceId" : "ref3"}, "lastname" : "Evans", "title" : "Vice President", "email" : "[email protected]" }] } },{ "attributes" : {"type" : "Account", "referenceId" : "ref4"}, "name" : "SampleAccount2", "phone" : "1234567890", "website" : "www.salesforce2.com", "numberOfEmployees" : "100", "industry" : "Banking" }] }

  1. Source:

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/requests_composite_sobject_tree.htm

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.