+ Start a Discussion
Vijay NagarathinamVijay Nagarathinam 

Delete attachment

Hi,

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.

Thanks,
Vijay
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.
http://blog.jeffdouglas.com/2010/03/03/passing-parameters-with-a-commandlink/

Hope this helps :)
Thanks!
AMit
Lokesh KumarLokesh Kumar
Try if below link sole your query .

https://developer.salesforce.com/forums/?id=906F000000096SfIAI

https://developer.salesforce.com/forums/?id=906F000000099XCIAY
Akshit HuriaAkshit Huria
<apex:commandLink action="{!DELETE}" value="Delete"  title="Delete" >      
                      <apex:param value="{!attachment_ID}" assignTo="{!aID}" name="aID" />
                  </apex:commandLink>


--------apex-----------

Public String aID {get; set; }

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