+ Start a Discussion

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[]{};

For anyone interested, here is some sample code to implement sending of attachments.  This should be enough to get anyone started.
global class DirectSales{
 WebService static void emailHerman() {
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new string[] {'gnewman@spotzer.com'};
   mail.setSenderDisplayName('Spotzer Studio');
   mail.setSubject('Creative RFP');
   mail.setHtmlBody('This is a sample email from salesforce to Herman');
   Attachment Att = [Select body, name from attachment where id = '00P20000001iX37'];
   Messaging.EmailFileAttachment[] fileAttachments = new Messaging.EmailFileAttachment[1];
   Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
      fileAttachments[0] = fileAttachment;
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
Would you mind posting an example on how to take the attachment of an InboundEmail object and process it / save it to the attachments table?  (ie, the reverse of this one)
Rasmus MenckeRasmus Mencke
If you want to take the attachments from an inbound email and save them into the attachment object you could do this. You would have to set your ParentID to the object you want the attachment to relate to, for example a case or contact.

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;
How would we use EmailFileAttachment in javascript ?