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

How to use Wrapper Class to select Attachments from visualforce page??
Hi All,
The scenario is something like:
I am trying to create an apex class, in which i have created a method to send an email with attachment with the selected files only.... for this i am also creating the visualforce page using inputcheckbox.....
the apex class is something like:
But i am getting an error "Error: Compile Error: Loop variable must be an SObject or list of Attachment"
public class Checkbox_Class
{
public Id oppr { get;set; }
public Checkbox_Class(ApexPages.StandardController ctrl)
{
oppr = ctrl.getRecord().Id;
}
List<Attachmentwrapper> AttachmentList = new List<Attachmentwrapper>();
List<Attachment> selectedAttachments = new List<Attachment>();
public List<Attachmentwrapper> getAttachments()
{
for (Attachment a : [select Id, Name, Body, BodyLength from Attachment where ParentId = :oppr])
{
AttachmentList.add(new Attachmentwrapper(a));
return AttachmentList;
}
}
public PageReference getSelected()
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{'ashish.garg@headstrong.com'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('ashish.garg@headstrong.com');
mail.setSenderDisplayName('CRM Support');
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setTargetObjectId('005Q0000000FR7f');
mail.setTemplateId('00XQ0000000QULj');
mail.saveAsActivity = false;
//selectedAttachments.clear();
for(Attachmentwrapper accwrapper : AttachmentList)
{
if(accwrapper.selected == true)
{
selectedAttachments.add(accwrapper.acc);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
else
{
return null;
}
}
public List<Attachment> GetSelectedAttachments()
{
if(selectedAttachments.size()>0)
return selectedAttachments;
else
return null;
}
public class Attachmentwrapper
{
public Attachment acc{get; set;}
public Boolean selected {get; set;}
public Attachmentwrapper(Attachment a)
{
acc = a;
selected = false;
}
}
}