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
MarkLevyMarkLevy 

Creating a Custom Related List for Attachments -- File URL?

I'm trying to create a custom related list for Attachments to work in a better way than the existing one for my purposes. My thought is to just make a visualforce page that shows the attachments (with links to view) on the object currently being viewed, however I'm not sure how to go about doing that for attachment URLs.

It looks like the URL of the file isn't a part of the attachment object: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_attachment.htm

Instead it would appear that the ID of the attachment has something to do with it, but it looks like it goes to a diferent domain to get that, for instance, on my org:
https://ORGNAME--c.na63.content.force.com/servlet/servlet.FileDownload?file=ATTACHMENTID

It would appear that this is the way to query the attachment ID, but the URL it's using worries me.. is there a way in APEX to get that URL? I'm imagining lets say in the instance I just hard code this to make the file url always https://ORGNAME--c.na63.content.force.com/servlet/servlet.FileDownload?file=ATTACHMENTID and then our server changes and is no longer na63 and it breaks...

Any thoughts on this? How can I get the file URL that isn't quite so messy as hard coding it and then having to fix it if our server changes?

Thanks!
Best Answer chosen by MarkLevy
MarkLevyMarkLevy
https://help.salesforce.com/articleView?id=custom_links_example_linking_to_documents.htm&type=0

It looks like you can just use a relative link for '/servlet/servlet.FileDownload?file=ATTACHMENTID'