0

We have a contact lookup field on Account object - which basically defines the primary contact of that account.

We have an integration to update account record and would need to update the primary contact in the same call. Is it possible to do ? External system does not have any reference to this primary contact and neither in salesforce (as external id).

I am trying to do as below

Account.Name = 'test'; //update account record
Account.Primary_Contact__r.FirstName = 'test first'; //update primary contact record

So basically it should be able to update both Account and its Primary Contact.

I found a way to do this using PATCH as mentioned here. But it requires another call from Account update.

2
2

TIL - You can update a specific parent object field while updating a child object by using a combination of

Composite resources are used to bundle multiple CRUD operations into a single REST call.

For your example, here is the POST body for endpoint /services/data/v51.0/composite I used in workbench:

{
"allOrNone" : true,
"compositeRequest" : [{
    "method" : "PATCH",
    "url" : "/services/data/v51.0/sobjects/Account/0014000000HQGCNAA5",
    "referenceId" : "UpdatedAccount",
    "body" : {  
        "Name" : "test"
    }
},{
    "method" : "PATCH",
    "referenceId" : "UpdatedContact",
    "url" : "/services/data/v51.0/sobjects/Account/0014000000HQGCNAA5/Primary_Contact__r",
    "body" : {  
        "FirstName" : "test first"
    }
}]
}

The response looks like this:

{
  "compositeResponse" : [ {
    "body" : null,
    "httpHeaders" : { },
    "httpStatusCode" : 204,
    "referenceId" : "UpdatedAccount"
  }, {
    "body" : null,
    "httpHeaders" : { },
    "httpStatusCode" : 204,
    "referenceId" : "UpdatedContact"
  } ]
}
2
  • Thanks. If there is no lookup value it will fail that particular resource, it is not creating a new one May 14 at 6:15
  • True. That isn't what you asked though
    – cropredy
    May 14 at 13:15

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.