I am displaying attachments to the screen using an iFrame

<apex:iframe src="{!URLFOR($Action.Attachment.Download, att)}" html-class="abCSS" height="400px" width="400px"/>

Some of the attachments don't display to the screen(documents), and we want to additionally have a download link so they can download the document to their computer.

Using a command button the attachments just open in a new window in the browser. We want the files to download to the computer.

I was trying to use an anchor tag, but the file doesn't download

<a download="{!URLFOR($Action.Attachment.Download, att)}"  href="#"  styleClass="btn">Download Attachment</a> 

Does anyone know how to get the file to download to the computer?

2 Answers 2


The second parameter in the URLFOR is an Id. It looks like you might be passing an object. Make sure that is an Id, or switch it to att.Id if that is an attachment object.

<a href="{!URLFOR($Action.Attachment.Download, att.Id)}" target="_blank" styleClass="btn">Download Attachment</a>

Please try below code,

<a href="/servlet/servlet.FileDownload?file={!attachmentInstance.Id}"  target="_blank" styleClass="btn">Download Attachment</a> 

Basically it will try to open attachment in a new tab. If it is image/pdf that can be opened in browser, it will open in new tab, otherwise it will download the file.

You must log in to answer this question.

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