You need to sign in to do that
Don't have an account?

Creating a VIEW link for Attachments
I have created a Attachment Manager type setup, and the only thing is I am not able to pass the ID of the attachment to a new window. It opens with nothing in it.
Any idea how I could fix this maybe?
<apex:actionStatus id="status" startText="Searching... please wait..."/> <apex:pageBlockSection title="Search Results" id="resultsBlock" columns="1"> <apex:pageBlockTable value="{!searchResults}" var="item" rendered="{!NOT(ISNULL(searchResults))}"> <apex:column headerValue="Delete"> <apex:commandLink action="{!deleteAttachment}" onclick="if(!confirm('Are you sure?')) return false;">Del <apex:param value="{!item.id}" name="idToDel" assignTo="{!AttachId}"/> </apex:commandLink> </apex:column> <apex:column value="{!item.id}" HeaderValue="Attachment ID" width="100"/> <apex:column headerValue="Name of Attachment (Click to view)" > <apex:outputLink value="{!URLFOR($Action.Attachment.Download,item.id)}" target="_blank"> View</apex:outputLink> </apex:column>
The code displays the list, as well as the option to Delete it, (and it works) however when I click on the View, it opens a new window but nothing is pulled over to view. ?? Any idea?
Hi Mark,
If you have to used $Action Global Variable for attachment, then standard controller should be "Attachment".
below is sample code
Hope this will help you.
[If it solves your problem, please mark it as solution]
Hey Sunil,
I have already set it as the controller. See full VF page code below.
So thanks for your reply, however i am still seeing the issue.
Any other suggestions.
Hi Mark,
Replace item id in<apex:outputlink value="{!$Action.Attachment.download,item.id }"/> with Attachment.id
After doing this, when you click on link it will display the attachment whose id is passed in URL.
You have used outputlink in pageblocktable. So it means you have List of attachment. Standard controller takes care of only single records whose id is passed in URL. If you iterating through list of attachments then replace the code with below code
<apex:outputlink value="/servlet/servlet.FileDownload?file={!item.id}" target="_blank">View</apex:outputlink>
Hope this will help you.
[If it solves your problem, please mark it as solution]
I have used the above code working fine. Thanks for your post. Is it possible to open attachment on new tab.