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

How to pass attachment Id from Visualforce page to Controller class
Hi all,
I am showing list of attachments against a record in the visualforce page, also showing a DELETE link before each attachment. Now i want to delete the particular attachment when clicking on DELETE button. can someone help me out.
<apex:column >
<apex:facet name="header">Attachment</apex:facet>
<table border = '0' cellspacing="0" cellpadding="0">
<tr><td><b><center><apex:outputLink value="/apex/AttachmentUpload?id={!card.time.id}" rendered="{!!(card.time.id == null)}">Upload</apex:outputLink></center></b><br/></td>
<td><apex:repeat var="attach" value="{!card.time.Attachments}">
<apex:outputLink value="/servlet/servlet.FileDownload?file={!attach.id}" target="_blank">
{!attach.Name}
</apex:outputLink> <b><a href="javascript:if (window.confirm('Are you sure?')) DeleteFile('{!attach.Id}');" style="font-weight:bold">Del</a></b><br/>
</apex:repeat></td></tr></table>
</apex:column>
Thanks,
Uday
I am showing list of attachments against a record in the visualforce page, also showing a DELETE link before each attachment. Now i want to delete the particular attachment when clicking on DELETE button. can someone help me out.
<apex:column >
<apex:facet name="header">Attachment</apex:facet>
<table border = '0' cellspacing="0" cellpadding="0">
<tr><td><b><center><apex:outputLink value="/apex/AttachmentUpload?id={!card.time.id}" rendered="{!!(card.time.id == null)}">Upload</apex:outputLink></center></b><br/></td>
<td><apex:repeat var="attach" value="{!card.time.Attachments}">
<apex:outputLink value="/servlet/servlet.FileDownload?file={!attach.id}" target="_blank">
{!attach.Name}
</apex:outputLink> <b><a href="javascript:if (window.confirm('Are you sure?')) DeleteFile('{!attach.Id}');" style="font-weight:bold">Del</a></b><br/>
</apex:repeat></td></tr></table>
</apex:column>
Thanks,
Uday
You can use <apex:param> to pass the ID to controller.
VF page :
<apex:outputlink action="{!delAttachment}" href="javascript:if (window.confirm('Are you sure?')) DeleteFile('{!attach.Id}');" style="font-weight:bold">Del
<apex:param name="contIdParam" value="{!attach.Id}" assignTo="{!IdChoosen}"/>
</apex:outputlink>
Apex Controller:
public String IdChoosen{get; set;}
public PageReference delAttachment()
{
Attachment AttachmenttoDel=new Attachment(id=contIdChosen);
delete AttachmenttoDel;
// Here you can again call Wrapper list method to reload
return null;
}
You can use the following link for more details :
http://bobbuzzard.blogspot.in/2011/07/passing-parameters-to-apex-method-from.html
Happy Coding!!!
All Answers
You can use <apex:param> to pass the ID to controller.
VF page :
<apex:outputlink action="{!delAttachment}" href="javascript:if (window.confirm('Are you sure?')) DeleteFile('{!attach.Id}');" style="font-weight:bold">Del
<apex:param name="contIdParam" value="{!attach.Id}" assignTo="{!IdChoosen}"/>
</apex:outputlink>
Apex Controller:
public String IdChoosen{get; set;}
public PageReference delAttachment()
{
Attachment AttachmenttoDel=new Attachment(id=contIdChosen);
delete AttachmenttoDel;
// Here you can again call Wrapper list method to reload
return null;
}
You can use the following link for more details :
http://bobbuzzard.blogspot.in/2011/07/passing-parameters-to-apex-method-from.html
Happy Coding!!!
As per help and support:
A parameter for the parent component. The < apex:param > component can only be a child of the following components:
< apex:actionFunction >
< apex:actionSupport >
< apex:commandLink >
< apex:outputLink >
< apex:outputText >
< flow:interview >
public class YourController
{
public List<AttachmentWrapper> wrappers{get; private set;}
...
public void refreshData()
{
wrappers = new List<AttachmentWrapper>();
//Rebuild your wrappers variable here
...
//EX. wrappers.add(new AttachmentWrapper(someAttachment, this));
}
public class AttachmentWrapper
{
public Attachment attach{get; private set;}
public YourController controller{private get; private set}
public AttachmentWrapper(Attachment attach, YourController controller)
{
this.attach = attach;
this.controller = controller;
}
public static delAttach()
{
delete attach;
controller.refreshData();
}
}
}
<apex:outputlink action="{!delAttachment}" href="javascript:if (window.confirm('Are you sure?')) DeleteFile('{!attach.Id}');" style="font-weight:bold">Del
<apex:param name="contIdParam" value="{!attach.Id}" assignTo="{!RowAttachmentId}"/>
</apex:outputlink>
Apex Controller:
public String RowAttachmentId {get; set;}
public PageReference delAttachment()
{
Attachment DeleteAttach=new Attachment(id=RowAttachmentId);
delete DeleteAttach;
return null;
}
above that way is very esay to delete the attachement @ uday K
thanks
Balu