How to insert order and orderitems in single rest call in salesforce?

Add an Order to an Existing Account


Add Order Products to an Existing Order


I want to achieve the above two using a single rest call..that is I wish to add order and orderitems at the same time .Any help would be highly helpful.Thanks.

  • From which system you are calling this API? You can create a custom REST API to insert both order and orderlineitem in salesforce and pass json data as parent child. – Muzammil Bajaria May 23 '19 at 10:53
  • Thanks for the information...I am newbie in salesforce can you provide an example for the same.And also can it be achieved by standard REST API in any way ? – user2828669 May 23 '19 at 15:27

I would do this using Salesforce composite API. . Composite api allows you to provide complex JSON for inserting/updating/deleting/searching different sobjects in the form of subrequests.

It also supports referenceId's in subrequests.

In a subrequest’s body, you specify a reference ID that maps to the subrequest’s response. You can then refer to the ID in the url or body fields of later subrequests by using a JavaScript-like reference notation.

which mean you can insert parent and child in same call using refrenceId

consider the documented example of inserting Parent Account and child contact in same call.

"compositeRequest" : [{
  "method" : "POST",
  "url" : "/services/data/v38.0/sobjects/Account",
  "referenceId" : "refAccount",
  "body" : { "Name" : "Sample Account" }
  "method" : "POST",
  "url" : "/services/data/v38.0/sobjects/Contact",
  "referenceId" : "refContact",
  "body" : { 
    "LastName" : "Sample Contact",
    "AccountId" : "@{refAccount.id}"

You can do same to create order, orderline item in same call

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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