You need to sign in to do that
Don't have an account?
GerhardNewman2
Sending Email attachments with API
My SF Winter 08 API documentation has this code sample http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_sendemail.htm
It refers to a type called EmailFileAttachment. But when I use the same code I get an error saying Error: Compile Error: Invalid type: EmailFileAttachment
The line causing the error is:
EmailFileAttachment[] fileAttachments = new EmailFileAttachment[1];
I am working in sandbox using API(12.0)
Am I doing something wrong, or has this type not been implemented?
The solution is:
Messaging.EmailFileAttachment[] fileAttachments = new Messaging.EmailFileAttachment[]{};
WebService static void emailHerman() {
String[] toAddresses = new string[] {'gnewman@spotzer.com'};
mail.setToAddresses(toAddresses);
mail.setSenderDisplayName('Spotzer Studio');
mail.setSubject('Creative RFP');
mail.setHtmlBody('This is a sample email from salesforce to Herman');
Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
fileAttachment.setBody(Att.body);
fileAttachment.setFileName(Att.name);
fileAttachments[0] = fileAttachment;
mail.setFileAttachments(fileAttachments);
}
If you want to store the text attachments as well, you would have to do that same for them.
if (email.binaryAttachments!=null && email.binaryAttachments.size() > 0) {
for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
Attachment a = new Attachment(ParentId = em[0].Id,
Name = email.binaryAttachments[i].filename,
Body = email.binaryAttachments[i].body);
insert a;
}
}