Using SObject Tree REST resource to update record
I'd like to update an Account and create a child Contact in a single transaction using REST API. Tried to use SObject Tree endpoint, but when I simply pass the Id in object body, I get:
Don’t specify the record ID. It’s created automatically and returned
in the response.
Is it even possible with SObject tree? Or perhaps the Composite resource with the mix of POST and PATCH with reference notation ("AccountId": "@{refAccount.id}"
) is the way to go? If so, is SObject Tree just a wrapper to Composite API?
rest-api composite sobject-tree
add a comment |
I'd like to update an Account and create a child Contact in a single transaction using REST API. Tried to use SObject Tree endpoint, but when I simply pass the Id in object body, I get:
Don’t specify the record ID. It’s created automatically and returned
in the response.
Is it even possible with SObject tree? Or perhaps the Composite resource with the mix of POST and PATCH with reference notation ("AccountId": "@{refAccount.id}"
) is the way to go? If so, is SObject Tree just a wrapper to Composite API?
rest-api composite sobject-tree
add a comment |
I'd like to update an Account and create a child Contact in a single transaction using REST API. Tried to use SObject Tree endpoint, but when I simply pass the Id in object body, I get:
Don’t specify the record ID. It’s created automatically and returned
in the response.
Is it even possible with SObject tree? Or perhaps the Composite resource with the mix of POST and PATCH with reference notation ("AccountId": "@{refAccount.id}"
) is the way to go? If so, is SObject Tree just a wrapper to Composite API?
rest-api composite sobject-tree
I'd like to update an Account and create a child Contact in a single transaction using REST API. Tried to use SObject Tree endpoint, but when I simply pass the Id in object body, I get:
Don’t specify the record ID. It’s created automatically and returned
in the response.
Is it even possible with SObject tree? Or perhaps the Composite resource with the mix of POST and PATCH with reference notation ("AccountId": "@{refAccount.id}"
) is the way to go? If so, is SObject Tree just a wrapper to Composite API?
rest-api composite sobject-tree
rest-api composite sobject-tree
asked 4 hours ago
Bart Juriewicz
1,416823
1,416823
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I don't believe this can be done via the sObject Tree resource. The documentation indicates that it's create-only:
Use the SObject Tree resource to create nested records that share a root record type. For example, in a single request, you can create an account along with its child contacts, and a second account along with its child accounts and contacts. Once the request is processed, the records are created and parents and children are automatically linked by ID.
and POST-only:
HTTP method
POST
(Emphasis mine).
Conversely, the sObject Composite takes a POST
request for itself, but allows you to specify the method for each individual subrequest.
Here's a variation on the example in the linked document and the example of Account-Contact junction linking above that successfully updates an existing Account and adds a new Contact:
{
"allOrNone" : true,
"compositeRequest" : [{
"method" : "PATCH",
"url" : "/services/data/v38.0/sobjects/Account/0013600001lwxdQAAQ",
"referenceId" : "NewAccount",
"body" : {
"Name" : "TestComposite"
}
},
{
"method" : "POST",
"referenceId" : "NewContact",
"url" : "/services/data/v38.0/sobjects/Contact",
"body" : {
"lastname" : "Doe",
"AccountId" : "0013600001lwxdQAAQ"
}
}]
}
Here, we actually have to specify the Id explicitly in both requests rather than using reference Ids. That's because the reference Id names the response body for each request, so if we did @{NewAccount.id}
(which works fine in a POST
create operation), we'd get an error since the PATCH
update response body is empty.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "459"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f245339%2fusing-sobject-tree-rest-resource-to-update-record%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I don't believe this can be done via the sObject Tree resource. The documentation indicates that it's create-only:
Use the SObject Tree resource to create nested records that share a root record type. For example, in a single request, you can create an account along with its child contacts, and a second account along with its child accounts and contacts. Once the request is processed, the records are created and parents and children are automatically linked by ID.
and POST-only:
HTTP method
POST
(Emphasis mine).
Conversely, the sObject Composite takes a POST
request for itself, but allows you to specify the method for each individual subrequest.
Here's a variation on the example in the linked document and the example of Account-Contact junction linking above that successfully updates an existing Account and adds a new Contact:
{
"allOrNone" : true,
"compositeRequest" : [{
"method" : "PATCH",
"url" : "/services/data/v38.0/sobjects/Account/0013600001lwxdQAAQ",
"referenceId" : "NewAccount",
"body" : {
"Name" : "TestComposite"
}
},
{
"method" : "POST",
"referenceId" : "NewContact",
"url" : "/services/data/v38.0/sobjects/Contact",
"body" : {
"lastname" : "Doe",
"AccountId" : "0013600001lwxdQAAQ"
}
}]
}
Here, we actually have to specify the Id explicitly in both requests rather than using reference Ids. That's because the reference Id names the response body for each request, so if we did @{NewAccount.id}
(which works fine in a POST
create operation), we'd get an error since the PATCH
update response body is empty.
add a comment |
I don't believe this can be done via the sObject Tree resource. The documentation indicates that it's create-only:
Use the SObject Tree resource to create nested records that share a root record type. For example, in a single request, you can create an account along with its child contacts, and a second account along with its child accounts and contacts. Once the request is processed, the records are created and parents and children are automatically linked by ID.
and POST-only:
HTTP method
POST
(Emphasis mine).
Conversely, the sObject Composite takes a POST
request for itself, but allows you to specify the method for each individual subrequest.
Here's a variation on the example in the linked document and the example of Account-Contact junction linking above that successfully updates an existing Account and adds a new Contact:
{
"allOrNone" : true,
"compositeRequest" : [{
"method" : "PATCH",
"url" : "/services/data/v38.0/sobjects/Account/0013600001lwxdQAAQ",
"referenceId" : "NewAccount",
"body" : {
"Name" : "TestComposite"
}
},
{
"method" : "POST",
"referenceId" : "NewContact",
"url" : "/services/data/v38.0/sobjects/Contact",
"body" : {
"lastname" : "Doe",
"AccountId" : "0013600001lwxdQAAQ"
}
}]
}
Here, we actually have to specify the Id explicitly in both requests rather than using reference Ids. That's because the reference Id names the response body for each request, so if we did @{NewAccount.id}
(which works fine in a POST
create operation), we'd get an error since the PATCH
update response body is empty.
add a comment |
I don't believe this can be done via the sObject Tree resource. The documentation indicates that it's create-only:
Use the SObject Tree resource to create nested records that share a root record type. For example, in a single request, you can create an account along with its child contacts, and a second account along with its child accounts and contacts. Once the request is processed, the records are created and parents and children are automatically linked by ID.
and POST-only:
HTTP method
POST
(Emphasis mine).
Conversely, the sObject Composite takes a POST
request for itself, but allows you to specify the method for each individual subrequest.
Here's a variation on the example in the linked document and the example of Account-Contact junction linking above that successfully updates an existing Account and adds a new Contact:
{
"allOrNone" : true,
"compositeRequest" : [{
"method" : "PATCH",
"url" : "/services/data/v38.0/sobjects/Account/0013600001lwxdQAAQ",
"referenceId" : "NewAccount",
"body" : {
"Name" : "TestComposite"
}
},
{
"method" : "POST",
"referenceId" : "NewContact",
"url" : "/services/data/v38.0/sobjects/Contact",
"body" : {
"lastname" : "Doe",
"AccountId" : "0013600001lwxdQAAQ"
}
}]
}
Here, we actually have to specify the Id explicitly in both requests rather than using reference Ids. That's because the reference Id names the response body for each request, so if we did @{NewAccount.id}
(which works fine in a POST
create operation), we'd get an error since the PATCH
update response body is empty.
I don't believe this can be done via the sObject Tree resource. The documentation indicates that it's create-only:
Use the SObject Tree resource to create nested records that share a root record type. For example, in a single request, you can create an account along with its child contacts, and a second account along with its child accounts and contacts. Once the request is processed, the records are created and parents and children are automatically linked by ID.
and POST-only:
HTTP method
POST
(Emphasis mine).
Conversely, the sObject Composite takes a POST
request for itself, but allows you to specify the method for each individual subrequest.
Here's a variation on the example in the linked document and the example of Account-Contact junction linking above that successfully updates an existing Account and adds a new Contact:
{
"allOrNone" : true,
"compositeRequest" : [{
"method" : "PATCH",
"url" : "/services/data/v38.0/sobjects/Account/0013600001lwxdQAAQ",
"referenceId" : "NewAccount",
"body" : {
"Name" : "TestComposite"
}
},
{
"method" : "POST",
"referenceId" : "NewContact",
"url" : "/services/data/v38.0/sobjects/Contact",
"body" : {
"lastname" : "Doe",
"AccountId" : "0013600001lwxdQAAQ"
}
}]
}
Here, we actually have to specify the Id explicitly in both requests rather than using reference Ids. That's because the reference Id names the response body for each request, so if we did @{NewAccount.id}
(which works fine in a POST
create operation), we'd get an error since the PATCH
update response body is empty.
edited 3 hours ago
answered 4 hours ago
David Reed
30.6k61746
30.6k61746
add a comment |
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f245339%2fusing-sobject-tree-rest-resource-to-update-record%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown