0

I have an app that calls the Salesforce REST API to retrieve attachments stored in Salesforce. It makes a call like this to get the attachment body:

/services/data/v52.0/sobjects/Attachment/00Pe0000008ELB4EAO/Body

I now need to do the same for an attachment that may or may not be deleted. I can query a deleted attachment like this and get some information about it:

/services/data/v52.0/queryAll/?q=select+body+from+Attachment+where+id='00Pe0000008ELB4EAO'

This returns a body like this -- note this response does not contain the actual file body:

{
    "totalSize": 1,
    "done": true,
    "records": [
        {
            "attributes": {
                "type": "Attachment",
                "url": "/services/data/v52.0/sobjects/Attachment/00Pe0000008ELB4EAO"
            },
            "Body": "/services/data/v52.0/sobjects/Attachment/00Pe0000008ELB4EAO/Body"
        }
    ]
}

But when I call /services/data/v52.0/sobjects/Attachment/00Pe0000008ELB4EAO/Body, I get a 404 Not Found status and the following response body:

[
    {
        "errorCode": "NOT_FOUND",
        "message": "The requested resource does not exist"
    }
]

Are there any workarounds I can consider?

1 Answer 1

1

It looks like when an attachment is deleted (Attachment.IsDeleted = true (services/data/v52.0/queryAll/?q=select+IsDeleted+,+body+from+Attachment+where+id='00Pe0000008ELB4EAO') ), the record goes to the Recycle Bin and the body gets hidden.

One of the option would be to restore the attachment, get the body, and delete the attachment again? Although it's not perfect from the audit point of view (the LastModifiedById and LastModifiedDate fields will be changed)

1
  • 1
    Yeah, it's not perfect, from an audit perspective and also because you're forced to use Apex to undelete (see salesforce.stackexchange.com/questions/117370). Given the absence of any other replies, this is probably the best answer possible, unsatisfying as it may be. Thanks! Sep 16, 2021 at 15:58

You must log in to answer this question.

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