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

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:

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:

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 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?

Best Answer chosen by MarkLevy

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