2

Trying a composite request to query related records in a bulk fashion using the referenceID relation. When multiple records are returned in the first query request, is there any way I can query the Contacts of all the Accounts returned from the first method?

My current composite Request which returns the Contacts of the first Account record from the first query method using the annotation @{refAccounts.records[0].Id}:

{
  "compositeRequest": [
    {
      "method": "GET",
      "url": "/services/data/v41.0/query?q=SELECT+Id,Name+FROM+Account+WHERE+Name+LIKE+'ABC%'+LIMIT+2",
      "referenceId": "refAccounts"
    },{
        "method" : "GET",
        "url" : "/services/data/v41.0/query?q=SELECT+Id,Name+From+Contact+WHERE+Account='@{refAccounts.records[0].Id}'",
        "referenceId" : "refContacts"                               
    }
    ]
}
4
  • Check out the last example [Here] (developer.salesforce.com/blogs/tech-pubs/2017/01/…). It might help you. It does same thing except unlike your query it only gets contact for 1 account. May 20 at 18:09
  • Thanks for the response. If you're referring to "AccountId" : "@{refAccount.id}" part, the refAccount reference is from a POST method which results in only one ID; so although it appears like we're using multiple records, it's actually just one ID that is getting related here. The GET method can result in multiple records within the "records" array and that's where the challenge lies.
    – Vignesh
    May 20 at 18:31
  • @Vignesh This is not possible out of the box, you'll have to do the transform yourself
    – identigral
    May 20 at 18:43
  • Thanks @identigral. I figured we can do something like "...IN+('@{QS01.records[0].Id}','@{QS01.records[1].Id}','@{QS01.records[2].Id}')" in the 2nd GET method in order to process more than one record from the 1st method. And we can also refer to @{QS01.totalSize} dynamically to get the total number of records in the 1st GET method. Some capability like "...IN+('@{QS01.records[0].Id}' .. '@{QS01.records[@{QS01.totalSize}-1].Id}')" would have been marvelous using the dot dot notation to include the entire collection. Anyways, I'll find some other way out.
    – Vignesh
    May 20 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.