+ Start a Discussion

How to get downloadable link for attachment?


Assume I have attachments for different types of salesforce object types (i.e. accounts, contacts ...). How can I get the downloadable link for those attachment? 
I can see different type of URLs for different type of attachment file types. i,e for a text file downloadable link in the UI is,
but for pdf it is,

I have a component with ApacheTika and later I can parse this downloadable link to that component. So that component can download attachment. 

Gaurav NirwalGaurav Nirwal
When requested from a valid session (i.e. after someone has logged in to salesforce) this URL (that includes the ID of the attachment) works:


If you create a text formula field on an object of this form:

HYPERLINK('/servlet/servlet.FileDownload?file=' + AttachmentId__c, 'View', '_blank')

the link can be displayed in default (layout based) UI. You will have to use an Attachment after trigger to store the AttachmentId on the object. The Attachment's ParentId tells you what its immediate parent object is and you can query as needed from there to find the object if it is not the immediate parent. (You need to decide what you want to do when there are multiple Attachments.)

But if you want to say email the link to a user that is not logged in to salesforce, you will need to use an "externally available" Document not an Attachment (though you could copy the Attachment content to a Document automatically in a trigger).

Thanks for response. Yes for sone files following url works.

I uploaded text file and jpeg image for an account. The jpeg image file id is 069i0000001dkl8 and it can't access via,

But it can acces via,

Can asume the user is always logged into the system. I just need download URL from api object or a way to generate download URL.

Thanks and Regards
any update on this?
Chuck H.Chuck H.
For anyone who may end up here looking for a solution, and not having luck with the older methods above...I was able to catch one of the redirect links and am using this with success to click and icon on a lightning page and download the associated file. Link is
https://<YOUR ORG HERE>.lightning.force.com/sfc/servlet.shepherd/version/download/<FILE ID HERE>?operationContext=S1