Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a requirement to save attachment received from email in Salesforce object using Email To Salesforce. I tried using the below code but attachment are not getting saved, when I checked using the system.debug() it shows null value for both binaryattachment and testattachment.

Is there any setting that I need to check? I tested this with both text file and image file as attachment.

public class EmailProcess implements Messaging.InboundEmailHandler 
  public Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.Inboundenvelope envelope) 
    system.debug('email.textAttachments:' + email.textAttachments); //null
    system.debug('email.binaryAttachments:' + email.binaryAttachments); //null
    List<Attachment> attList = new List<Attachment>();
    //Assigned parentId 
    system.debug('parentId' +  parentId); //Shows record Id
    for (Messaging.Inboundemail.BinaryAttachment file : email.binaryAttachments) 
      Attachment attachment = new Attachment();
      attachment.Name = file .fileName;
      attachment.Body = file .body;
      // some hardcoded or id extracted from email reference
      attachment.ParentId = parentId;
      attList .add(attachment);
   if(attList .size()>0)
     insert attList;
share|improve this question
up vote 4 down vote accepted

When you add (or edit) the email handler class via the email service definition you get a choice of what sort of attachments should be passed to it as shown below. Check that setting.

email service page

share|improve this answer
thank you very much now its working. – Lavanya Sanathkumar Aug 25 '14 at 13:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.