function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vijay NagarathinamVijay Nagarathinam 

Delete attachment


I want to show the all the attachments in a visualforce page. If I click "X" image then corresponding attachment will be deleted in salesforce.

User-added image
Please let me know how to achieve this.

Amit Singh 1Amit Singh 1
Hello Vijay,

You can do this using Apex:commandLink when you will click on the cross button pass the attachment id in parameter and call apex class method which will be responsible for deleting the attachment.

Hope this helps :)
Lokesh KumarLokesh Kumar
Try if below link sole your query .
Akshit HuriaAkshit Huria
<apex:commandLink action="{!DELETE}" value="Delete"  title="Delete" >      
                      <apex:param value="{!attachment_ID}" assignTo="{!aID}" name="aID" />


Public String aID {get; set; }

public void DELETE()
       Attachment attach=new Attachment ();
       attach=[select id from Attachment where id=:aID];
        delete attach;