1

I need to reference a third to one of two other requests. So there's a Publication_Subscription__c which has two properties:

  1. Contact__c
  2. Lead__c

Always one of both exist and the other is null. So it's like a conditional (Left) join. I need to use a composite request to find the contact/lead with a given e-mail and to return all publication-subscriptions which have either that lead or contact assigned.

I have tried this:

post url: .../services/data/v53.0/composite

{
  "allOrNone": "false",
  "compositeRequest": [
    {
      "method": "GET",
      "url": "/services/data/v53.0/query?q=SELECT+Id+FROM+Contact+WHERE+Email+=+'jon.doe%40gmail.com'+AND+RecordTypeId+=+'0121x0000030snIAAQ'+LIMIT+1",
      "referenceId": "CurrentContact"
    },
    {
      "method": "GET",
      "url": "/services/data/v53.0/query?q=SELECT+Id+FROM+Lead+WHERE+Email+=+'jon.doe%40gmail.com'+AND+RecordTypeId+=+'0121x0000030snIAAQ'+LIMIT+1",
      "referenceId": "CurrentLead"
    },
    {
      "method": "GET",
      "url": "/services/data/v53.0/query?q=SELECT+Lead__c,+Contact__c,+Id,+Subscription_Status__c,+Subscription_Date_dt__c,+ExtId__c,+Name+FROM+Publication_Subscription__c+WHERE+((Contact__c+=+'@{CurrentContact.records[0].Id}')+OR+Lead__c+=+'@{CurrentLead.records[0].Id}')",
      "referenceId": "Publications"
    }
  ]
}

But i get a 400 in the request that doesn't return a record:

"message": "Invalid reference specified. No value for CurrentLead.records[0].Id found in CurrentLead. Provided referenceId ('CurrentLead.records[0].Id') must start with a letter or a number, and it can contain only letters, numbers and underscores ('_')."

How can i modify the query to ensure that the related query returned at least one record(i tried @{CurrentContact.totalSize} > 0 but it didn't work either: "unexpected token: '1'").

1 Answer 1

2

One option in this case is to send two separate subrequests. One subrequest would search for Publications using the Contact while the other would use the Lead.

Then you'd need to check which of those two subresponses has httpStatusCode == 200 and which has httpStatusCode == 400.

Your request:

{
  "allOrNone": "false",
  "compositeRequest": [
    {
      "method": "GET",
      "url": "/services/data/v53.0/query?q=SELECT+Id+FROM+Contact+WHERE+Email+=+'jon.doe%40gmail.com'+AND+RecordTypeId+=+'0121x0000030snIAAQ'+LIMIT+1",
      "referenceId": "CurrentContact"
    },
    {
      "method": "GET",
      "url": "/services/data/v53.0/query?q=SELECT+Id+FROM+Lead+WHERE+Email+=+'jon.doe%40gmail.com'+AND+RecordTypeId+=+'0121x0000030snIAAQ'+LIMIT+1",
      "referenceId": "CurrentLead"
    },
    {
      "method": "GET",
      "url": "/services/data/v53.0/query?q=SELECT+Lead__c,+Contact__c,+Id,+Subscription_Status__c,+Subscription_Date_dt__c,+ExtId__c,+Name+FROM+Publication_Subscription__c+WHERE+Contact__c+=+'@{CurrentContact.records[0].Id}'",
      "referenceId": "PublicationsFromContact"
    },
    {
      "method": "GET",
      "url": "/services/data/v53.0/query?q=SELECT+Lead__c,+Contact__c,+Id,+Subscription_Status__c,+Subscription_Date_dt__c,+ExtId__c,+Name+FROM+Publication_Subscription__c+WHERE+Lead__c+=+'@{CurrentLead.records[0].Id}'",
      "referenceId": "PublicationsFromLead"
    }
  ]
}

And a possible response:


{
    "compositeResponse": [
        {
            "body": {
                // No contact found
                "records": []
            },
            "httpStatusCode": 200,
            "referenceId": "CurrentContact"
        },
        {
            "body": {
                // Some lead found
                "records": [{ ... }]
            },
            "httpStatusCode": 200,
            "referenceId": "CurrentLead"
        },
        {
            "body": {
                // Some error message
            },
            "httpStatusCode": 400,
            "referenceId": "PublicationsFromContact"
        },
        {
            "body": {
                // Your publications from the lead
            },
            "httpStatusCode": 200,
            "referenceId": "PublicationsFromLead"
        }
    ]
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .