I'm trying to create a custom attachments list for the Account object via a visualforce page to replace the standard attachments related list Salesforce provides, which makes finding an attachment very difficult with all children attachments rolling up to the parent.

At this point, I have a custom visualforce page which lists only attachments associated with the account, ignoring all children attachments. I'm trying to reuse standard actions instead of having to recreate them in a controller. So, I have added the hyperlinks to View and Edit the attachment, but I'm having issues with the Delete attachment hyperlink, which is supposed to call the deleteredirect.jsp, but it needs a CONFIRMATIONTOKEN.

I tried to use URLFOR(), but it's not well documented and I'm not sure it works with Attachment. I've also searched through the Salesforce Apex documentation and through the web, but I couldn't find the correct answer. If I missed it for any reason, please feel free to point me to the right direction.

Any suggestions?



2 Answers 2


I had a very similar problem (mine was with Task Attachments) and in my research I came across this unanswered question. Since I was able to solve it I thought I'd share what I found and hopefully save someone from all of the searching I had to do! I was able to completely replicate the standard Attachment Actions using the following lines:

<apex:outputlink value="/{!att.id}/e?retURL=%2F{!task.id}" target="_parent">Edit</apex:outputlink>&nbsp;|&nbsp;

<apex:commandLink onclick="return confirm('Are you sure?');" action="{!URLFOR($Action.Attachment.Delete,att.id,[retURL='/'+task.id], TRUE)}" target="_parent" Value="Del" />&nbsp;|&nbsp;

<apex:outputlink value="{!URLFOR($Action.Attachment.Download,att.id)}" target="_blank">View</apex:outputlink>

You can write your own method in apex controller of the page to delete attachment.

  1. Createdelete as a command link and call a controller method and pass attachment ID as parameter
  2. In the controller method delete attachment and rerender the list of attachments in page

You must log in to answer this question.

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