I'll preface this by saying I'm not a developer but I'm working with our engineering team to help automate our process. Thier question to me is can we create multiple related records across multiple objects and have them related to each other using Salesforce's API.
Here's an Example:
- Create Case 1
- Create Contact 1
- Create Case Relationship1 (junction object that relates Contact1 to Case 1)
- Create Contact 2
- Create Case Relationship (relate Contact2 to Case 1)
Is this doable without returning IDs then creating records based on the ID or can we send all of this to Salesforce to create at the same time?
If so is there specific documentation on how to do this?
Thanks!
Best Answer
I believe the thing you are looking for is the
composite
resource available through Salesforce's REST API.The "composite" resource allows you to both:
Two pages of documentation I'd point you to are:
The two links end up giving you very similar information. In the interest of ease of reference (since links have a habit of going dead over time), the important bits are as follows.
The url you'd use to make a composite request is
https://<your instance here>.salesforce.com/services/data/<api version>/composite/
My sandbox, for example, is on the "cs52" instance, and the current version of Salesforce's APIs is "v43.0", so if I wanted to make a request to my sandbox, the url I'd use would be
https://cs52.salesforce.com/services/data/v43.0/composite/
The example JSON body given in that second link is:
For each subrequest, there's also documentation that covers what you can specify. This page also tells us the following...
An inline recap of the other information on that page:
@{}
syntax and dot-notation to access a specific field/services/data/<api version>/sobjects/<SObject name>/