2

I was able to retrieve the response from the Blob Retrieve endpoint

/services/data/v55.0/sobjects/Attachment/OOPXXXXXXXXXXXXXXX/Body

but when i use composite request

endpoint: /services/data/v55.0/composite

{
"allOrNone": false,
"compositeRequest": [
    //this is fine
    {
        "method": "GET",
        "url": "/services/data/v55.0/sobjects/Attachment/OOPXXXXXXXXXXXXXXX",
        "referenceId": "attacmentInfo"
    },
    //this is error
    {
        "method": "GET",
        "url": "/services/data/v55.0/sobjects/Attachment/OOPXXXXXXXXXXXXXXX/Body",
        "referenceId": "blobInfo"
    }]
}

it returns error:

Expected ':' instead of '}'

How can I achieve this in composite API?

EDIT:

Tried using workbench and the response is

{
"compositeResponse": [{
    // response: get attachment
    "body": {
        "attributes": {
            "type": "Attachment",
            "url": "/services/data/v55.0/sobjects/Attachment/OOPXXXXXXXXXXXXXXX"
        },
        //attachment details
        ....
    },
    "httpStatusCode": 200,
    "referenceId": "attacmentInfo"
},
// response: blob retrieve
{
    "body"
}]
} [{
    "message": "(was java.lang.NullPointerException)",
    "errorCode": "JSON_PARSER_ERROR"
}]

Our rest client cannot parse the invalid JSON structure response from Salesforce hence it's throwing Expected ':' instead of '}'

1 Answer 1

4

As the documentation states:

Composite is supported for the following resources.

  • All sObject resources (/services/data/vXX.X/sobjects/), including sObject Rows by External ID and excluding sObject Blob Retrieve
  • The Query resource (/services/data/vXX.X/query/?q=soql)
  • The QueryAll resource (/services/data/vXX.X/queryAll/?q=soql)
  • The sObject Collections resource (/services/data/vXX.X/composite/sobjects). Available in API version 43.0 and later.

(Emphasis added)

Further, the Get Records Using sObject Collections states:

The sObject Blob Retrieve resource isn’t compatible with Composite API requests, because it returns binary data instead of data in JSON or XML formats. Instead, make individual sObject Blob Retrieve requests to retrieve blob data. (Emphasis added)

You must retrieve one Blob at a time, as there is no API for retrieving them in bulk, unfortunately.

2
  • I guess I overlooked the documentation. We choose to use the custom API approach and planning to send the base 64 encoded via the API response. Is there a limit about the response of a json? Checked here: stackoverflow.com/questions/8937516/… it seems there are no max limit, is it same behavior with Salesforce?
    – Rival
    Commented Feb 18, 2023 at 3:06
  • 1
    @Rival Depends on if you use automatic serialization or not. The maximum size of any response is 15MB from Apex, but you only have 6MB of heap memory to use, too. So, ultimately, you're probably going to be limited to returning files that are about 4MB or less.
    – sfdcfox
    Commented Feb 18, 2023 at 4:09

You must log in to answer this question.

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