You need to sign in to do that
Don't have an account?
Able to choose what attachments get sent from Notes & Attachments
I have create a Visualforce Page and Apex Class to send an email from Opportunities with an attachment from the Notes and Attachments section. It works to send all the Attachments in the Notes and Attachments section, I want to be able to choose which attchments get sent. Any ideas on how I can select the Attachment and only send the ones I want. My Class is below.
Apex Class
public class email_class{
public email_class(ApexPages.StandardController controller) {
}
Public string ToAddresses {get;set;}
Public string CCAddresses {get;set;}
Public string opportunityId {get;set;}
Public string subject {get;set;}
public string email_body {get;set;}
public string emailTo {get;set;}
public string emailCC {get;set;}
Public PageReference send(){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); // set the to address
mail.setToAddresses(new String[] {emailTo});
mail.setCcAddresses(new String[] {emailCC}); //set the cc address
mail.setSubject(subject);
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setPlainTextBody(email_body);
mail.setWhatId(opportunityId);// Set email file attachments
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for (Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = :opportunityId]){ // Add to attachment file list
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);}
mail.setFileAttachments(fileAttachments);// Send email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
return null;
}
}
On what basis do you want to select Attachments that need to be send.
Is there anything unique in those attachments on the basis of which we can filter the query or Do you want to select the attachment from your VF page.
Please clear the above query so that we can provide you any help.
Please let us know the filter criteria on the attachment which youn want to send.
Thanks,
Abhishek
If you are already selecting the attachments on VF page than there must be a wrapper class included in ypour controller class but i cant see it.
So you have to create a wrapper class in your controller class that will bind the selected attachments from VF page to controller class and after that you will have to change the logic a bit to only send the selected attachment.
Please take help on wrapper class with below link :
https://developer.salesforce.com/page/Wrapper_Class
If you need me to help you with the code than please contact me on Gmail or Skype :
Gmail : abhibansal2790@gmail.com
Skype : abhishek.bansal
Thanks,
Abhishek