This might be solved easily, but cant find a solution..

I have a record with an attachment. This attachment is an HTML file.

When I click on the "view" link in SalesForce, it downloads it. Is it possible to display it instead?

Create an URL based on the attachment ID?...

3 Answers 3


Construct the URL using a custom controller


Depending on the installed plugins or browser settings this will either display in the browser window or download. This will bypass the attachment detail page.

  • 1
    What do you think about using getFileFieldURL(attachmentId, 'Body'); from the URL class? Feb 25, 2014 at 4:13
  • 1
    I get the following error in the dev console: 22:56:03:051 FATAL_ERROR System.HandledException: Invalid parameter value "Body" for parameter "fieldName".
    – Eric
    Feb 25, 2014 at 4:21
  • Maybe 'AttachmentBody'? Feb 25, 2014 at 4:21
  • Nope same error...
    – Eric
    Feb 25, 2014 at 4:22

Honestly it's messy, and brower behaviour will not be consistent, so I woudn't lose sleep over this one.

But if you are willing to drop a custom Visualforce Page onto the record layout, I think you can create an apex:iframe component with the src attribute set to the download URL. For an attachment living on the record, you can get the URL in Visualforce (see Valid Values for the $Action Global Variable):

URLFOR($Action.Attachment.Download, attachmentId)



So... After some unsuccesful testing, I deployed to PROD because..well.. it needed to be deployed. And the page is displayed and not downloaded when in PROD.

Weird but works at the end of the day..

So same type of link in Sandbox and Prod:

  • Downloaded in Sandbox
  • Displayed in Prod

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .