Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Salesforce Case object with nested relationships using REST API

I am attempting to create a new Case object using the REST API but need to find out how to format the JSON body to pass in nested SObjects.

It's not apparent in the Docs, and I can't seem to find any examples. Anyone have any pointers or have done this before?

The SF web UI uses a text lookup field to set the (related) Contact and Account, and I need to figure out how to either bypass the need for a lookup or embed the SObjects of the related records in the JSON.

[{"message":"The value provided for foreign key reference Contact is not a nested SObject","errorCode":"INVALID_FIELD"}]
like image 226
notbrain Avatar asked May 01 '12 22:05

notbrain


People also ask

How do I create a case in REST API?

Call the create Case RestAPI with access_token from the previous step. Use the instance_url and the access_token from the previous step to make the call to create a Case. Use access_token in Authorization Header as Authorization: Use the <instance_url> along with the endpoint to access the intended API.

What is composite REST API in Salesforce?

Executes a series of REST API requests in a single call. You can use the output of one request as the input to a subsequent request. The response bodies and HTTP statuses of the requests are returned in a single response body. The entire series of requests counts as a single call toward your API limits.


2 Answers

Figured it out by simply setting the AccountId and ContactId attributes on the new Case object.

like image 56
notbrain Avatar answered Oct 21 '22 18:10

notbrain


I also haven't seen any documentation about this, but if you look at the object metadata returned by the REST API for any standard object, it seems that the suffix 'Id' is appended to any field of type "reference". For example, Case has OwnerId, LastModifiedById, CreatedById, etc. This suffix is not present in the field names displayed in the browser interface. The WSDL for the SOAP API includes both the ID as a simple element of type "ID", as well as a complex child element for nesting the actual record.

like image 28
karlgold Avatar answered Oct 21 '22 16:10

karlgold