2

I am trying to insert standard Account records at the same time as child records (designed by relation Related_Person_Account_Relations__r). I am using the Composite tree Account endpoint (/services/data/v50.0/composite/tree/Account/) with following payload :

 {
    "records" : [{
      "attributes" :{ "type" : "Account", "referenceId" : "account_ref" },
      "FirstName" : "Joan",
      "LastName" : "OfArk",
      "Salutation" : "Mrs.",
      "Specialty__r" : {"ExternalId__c":"GERIATRE_FR"},
      "Related_Person_Account_Relations__r" : {
        "records" : [{
          "attributes" : { "type" : "ContactAccountRelation__c", "referenceId" : "professional_activity_ref" }
        }]
      }
    }]
  }

This callout unfortunately fails with error

statusCode: INVALID_FIELD message: Cannot reference a foreign key field Specialty__r.

If I specify Specialty__c id instead of ExternalId__c, it works fine, but I would like to be able to pass an external id rather than the actual Id that I might not always have access to. Is there anyway to reference lookup records with an external Id in a composite callout ?

0

This API only allows inserts, not associations to records via External ID. Instead, you can use the Composite API to retrieve the Specialty__c by External ID, and then use that value by reference ID in your related object creation. That would look something like this:

{
    "compositeRequest": [{
        "method": "GET",
        "url": "/services/data/v49.0/sobjects/Specialty__c/ExternalId__c/GERIATRE_FR",
        "referenceId": "refSpecialtyGERIATRE_FR"
    },
    {
        "method": "POST",
        "url": "/services/data/v49.0/sobjects/Account/",
        "referenceId": "AccountRef",
        "Specialty__c": "@{refSpecialtyGERIATRE_FR.Id}",
        ...
    },
    ...
    ]
}

You can (and should) read more about this in the documentation. You'll need to specify the Relations object as separate records in the list instead of nested objects.

You can also use the graphs API as well, although I'm not nearly as familiar with it.

1
  • Ah interesting @sfdcfox, so no support for External Id lookups Dec 14 '20 at 21:33

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.