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

Add more than one attachment from different objects
Hi Everyone,
I have got a class that sends an email and it works really well adding the files from the related notes and attachments. However, I would also like to include a file from the documents object.
This file will have a fixed id of 015D0000003rgYq
I tried something like this, but cannot get it to work:
How can I reference this in my code and then get it to attach both files from the different objects?
A sample of the code I currently have is:
I have got a class that sends an email and it works really well adding the files from the related notes and attachments. However, I would also like to include a file from the documents object.
This file will have a fixed id of 015D0000003rgYq
I tried something like this, but cannot get it to work:
Document doc = [SELECT Id FROM Document WHERE Id = '015D0000003rgYq'];
How can I reference this in my code and then get it to attach both files from the different objects?
A sample of the code I currently have is:
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); List<String> toaddress = new List<String>(); toaddress.add(string.valueof(cf.Email_to_send_confirmation_to__c)); mail.settoaddresses(toaddress); mail.setReplyTo('trainingbookings@certsure.com'); mail.setSenderDisplayName('Certsure Training'); mail.setBccSender(false); mail.setUseSignature(false); mail.saveAsActivity = true; mail.setSubject(subject); mail.setHtmlBody(htmlBody); //Set email file attachments List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>(); for (Attachment a : [select Id, Name, Body, BodyLength from Attachment where ParentId = :oppr]) { // 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;
All Answers
You are a legend! Thank you!
Ta
Joe