Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

Construct the URL using a custom controller

/servlet/servlet.FileDownload?file={ATTACHMENTID}

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.

share|improve this answer
    
What do you think about using getFileFieldURL(attachmentId, 'Body'); from the URL class? –  user320 Feb 25 at 4:13
    
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 at 4:21
    
Maybe 'AttachmentBody'? –  user320 Feb 25 at 4:21
    
Nope same error... –  Eric Feb 25 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)

screenshot

share|improve this answer
up vote 0 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.