function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC_2706SFDC_2706 

Open attachment(from templates object) on a button click...!!

Hi Experts,
I have one requirement where I am storing attachments in notes and attachments section of any record in Template custom object. After that I also want to have a custom URL type field in some custom object . The value will be a direct link to download the attachment file. Whenever any user clicks the link, the attachment should get dowloaded.
I know we can do with the custom formula field, but struggling to get the exact URL code for it.

How to do that? Any idea. I have access to all the fields in attachment record. How to get the download link from that? Please help.
RatanRatan
https://c.ap1.content.force.com/servlet/servlet.FileDownload?file=00P9000000kIM48

//00P9000000kIM48 pass attachment Id here
or 
 
HYPERLINK('/servlet/servlet.FileDownload?file=' + AttachmentId__c, 'View', '_blank')

or
 
<apex:outputLink value="{!URLFOR($Action.Attachment.Download, yourAttachment.id)}">

 
SFDC_2706SFDC_2706
Hi Ratan,

Thanks for your response. But unfortunately couldn't get through. Getting this below error :

URL No Longer Exists
You have attempted to reach a URL that no longer exists on salesforce.com. 

You may have reached this page after clicking on a direct link into the application. This direct link might be: 
• A bookmark to a particular page, such as a report or view 
• A link to a particular page in the Custom Links section of your Home Tab, or a Custom Link 
• A link to a particular page in your email templates 

If you reached this page through a bookmark, you are probably trying to access something that has moved. Please update your bookmark. 
If you reached this page through any of the other direct links listed above, please notify your administrator to update the link. 
If you reached this page through a link on our site, please report the broken link directly to our Support Team and we will fix it promptly. Please indicate the page you were on when you clicked the link as well as any other related information. We apologize for the inconvenience. 
Thank you again for your patience and assistance. And thanks for using salesforce.com!


- HYPERLINK('/servlet/servlet.FileDownload?file=' + AttachmentId__c, 'View', '_blank') :
In this scenario what should i actually need to pass..?
RatanRatan
HYPERLINK('/servlet/servlet.FileDownload?file=' + AttachmentId__c, 'View', '_blank') :

replace AttachmentId__c with your Attachment Id