function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GerhardNewman2GerhardNewman2 

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?

GerhardNewman2GerhardNewman2

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.setToAddresses(toAddresses);
   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();
      fileAttachment.setBody(Att.body);
      fileAttachment.setFileName(Att.name);
      fileAttachments[0] = fileAttachment;
   mail.setFileAttachments(fileAttachments);
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
 }
}
paul-lmipaul-lmi
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;
}
}
prog_irfanprog_irfan
How would we use EmailFileAttachment in javascript ?