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
Sukhdeep SinghSukhdeep Singh 

I am using delete for attachments, But Its not working

<td align="center"  style="font-weight: bold;color:Red;"><a href="{!URLFOR($Action.Attachment.delete, a.Id)}">Delete</a></td>

I am getting Error: Field $Action.Attachment.delete does not exist. Check spelling
Please suggest, How can I delete
Best Answer chosen by Sukhdeep Singh
Balaji Chowdary GarapatiBalaji Chowdary Garapati

@Sukhdeep Singh:

  Hi,

   There is no Action available for attachment object except download, the valid values were in the below link:

http://www.salesforce.com/docs/developer/pages/Content/pages_variables_global_action_valid_values.htm

Looks like you were trying to do that from a Visualforce page, so  you can use a method from controller to delete attachment which can be called from the td tag:

<td .... onclick="deleteAttachment({!a.id});" />
or you can call onclick from anchor tag its self
<apex:actionFunction name="deleteAttachment" action="your controller method">
<apex:param name="attachmentIdParam" value="" assignTo="{!yourvariablefromController}" />
</apex:actionFunction>
 

Controller:

public pageReference yourControllerMethod(){

try{
Attachment att=new Attachment(id=yourvariablefromController);
delete att;}catch(Exception e){
//handle your error
}
return null;
}
Hope this helps:


Thanks,
Balaji

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati

@Sukhdeep Singh:

  Hi,

   There is no Action available for attachment object except download, the valid values were in the below link:

http://www.salesforce.com/docs/developer/pages/Content/pages_variables_global_action_valid_values.htm

Looks like you were trying to do that from a Visualforce page, so  you can use a method from controller to delete attachment which can be called from the td tag:

<td .... onclick="deleteAttachment({!a.id});" />
or you can call onclick from anchor tag its self
<apex:actionFunction name="deleteAttachment" action="your controller method">
<apex:param name="attachmentIdParam" value="" assignTo="{!yourvariablefromController}" />
</apex:actionFunction>
 

Controller:

public pageReference yourControllerMethod(){

try{
Attachment att=new Attachment(id=yourvariablefromController);
delete att;}catch(Exception e){
//handle your error
}
return null;
}
Hope this helps:


Thanks,
Balaji

This was selected as the best answer
Sukhdeep SinghSukhdeep Singh
Thanks Balaji,

Your idea worked for me i used below code

<td align="center" style="font-weight: bold;color:Red;">
    <apex:commandLink value="Delete" action="{!deleteAttachment}" >
        <apex:param name="var" value="{!a.id}" assignTo="{!var}"/>
    </apex:commandLink>
</td>