+ Start a Discussion
francisco.sanchezfrancisco.sanchez 

How to get downloadable link for attachment?

Hi,

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,
https://c.na15.content.force.com/sfc/servlet.shepherd/version/download/068i0000001hvwC?asPdf=false&operationContext=CHATTER
but for pdf it is,
https://c.na15.content.force.com/servlet/servlet.FileDownload?file=00Pi0000004wHwY

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

Thanks!
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:

/servlet/servlet.FileDownload?file=00PM0000001fH6h

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).
francisco.sanchezfrancisco.sanchez
Hi,

Thanks for response. Yes for sone files following url works.
/servlet/servlet.FileDownload?file=00PM0000001fH6h

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

But it can acces via,
https://c.na15.content.force.com/sfc/servlet.shepherd/version/download/068i0000001hwPn?asPdf=false&operationContext=CHATTER 

Note:
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
francisco.sanchezfrancisco.sanchez
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