You need to sign in to do that
Don't have an account?

Trigger to get download link/url from attachments in salesforce?
Hi,
I'm trying to write a trigger that will give me the URL to an attachment on a custom object.
I made a formula text field on a custom object with this formula:
HYPERLINK('/servlet/servlet.FileDownload?file=' + AttachmentId__c, 'View', '_blank')
But the second step is difficult and I can't seem to get it to work. I want a link of the attachment to display. I want to create a after insert trigger but I can't get it to work.. I hope someone knows a solution for this..
Kind regards
Anyways, for that you can create a formula field and add
HYPERLINK('/apex/{yourvisualforcename}?id='+ Id, 'Images Preview')
All Answers
Thank you
Thank you for your reaction.
I have a custom object(Employee) where employees upload their receipts in the Notes & Attachments section of that custom object (Employee). But if the managers make a view of the records within the custom object (Employee) the Notes & Attachments can't show up in the view. So I created a formula text field with a link/url to the image the employees uploaden with Notes & Attachments. The formula above works but only for one attachment.. I want this to be dynamically so that for every record the image can show up in the custom field with formula..
I hope the story above is understandable.. @logontokartik
Thank you in advantage..
Cheers
Create a Visualforce Page that you can add as section on your Employee Object, that will show the preview of all the Attachment Images .
Below is the Sample I created for you. (Change the Test_Object__c to your Custom Object)
Here is the Controller - In the controller you can also filter attachments based on Content Type (png, jpg, jpeg etc).
Add the Visualforce Page as section to your Employee Detail page. and you should see all the images shown up on it. You dont need to write a trigger or manage additional fields now. And the page is resuable on any Object.
Hope this helps.
Since the hyperlink will refer to only one attachment you can show the attachment just for one (ex. last created attachment) ,There is no way to do that with one hyperlink , you need to create a visualforce page which shows the all attachments of the specific Employee with a downloadable outputlink.
The page is generally accesible from URL /apex/{yourvisualforcepagename}
You can then display the custom link on the Page Layout in the Custom Links section.
Please mark the above as solved if it solved your problem.
Thank you.
Anyways, for that you can create a formula field and add
HYPERLINK('/apex/{yourvisualforcename}?id='+ Id, 'Images Preview')
I am looking to build a trigger/field/link which takes me to Attachments from the emails.
My question - https://developer.salesforce.com/forums?state=id#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Visualforce_Development&criteria=OPENQUESTIONS&id=906F0000000BWk3IAG
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.