Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

1 Answer 1

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 at 13:52

Your Answer

 
discard

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.