2

Salesforce's developer documentation for the attachment object says (at the bottom of the page, emphasis mine):

However, you can't receive the Body field for multiple records in a single query() call. If your query returns the Body field, your client application must ensure that only one row with one Attachment is returned; otherwise, an error occurs.

Consider the following query:

SELECT Id, Name, Body FROM Attachment WHERE Id = '00Pp000000BH3TJEA1' LIMIT 1

The query executes without error and returns the correct record with the correct name etc. Unfortunately, the Body field only contains this:

{/services/data/v36.0/sobjects/Attachment/00Pp000000BH3TJEA1/Body}

I was expecting a base64-encoded attachment body, but instead just get a URL which I'm sure I could pass into the REST API to get what I want, but we aren't using the REST API, and I can reproduce this behaviour everywhere I can run SOQL queries, whether it's the CLI, the C# client library and even the developer console, both in a sandbox and our production environment, and for any attachment, using a system admin account.

I'm selecting a single attachment by ID as well as using "LIMIT 1", and this query definitely returns only one record. What am I doing incorrectly that is preventing the actual attachment Body from being included?

2

You're looking at the SOAP API documentation. To get a file's content in the REST API, you always use the URL as you've seen it. This is documented in sObject Blob Retrieve and Get Attachment Content from a Record.

  • Gah, it even says "SOAP API Documentation" right there at the top of the page. Ouch. We're actually using the DeveloperForce C# client library which doesn't seem to have any way to query attachment contents, so I guess we'll have to go back to using the REST API directly :( – Matt Wanchap Feb 27 at 5:43

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.