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
BittusBittus 

How to create an inbound email service to create records from the data present in attached file,

Hi,

Actually i need to generate records in account object based on the data present in the attached file, which wll be sent to Salesforce through email. I am trying to do so using Inbound Email Service, but am only able to read the body of the email but not the attachment data.
sfdcsushilsfdcsushil
Are you not able to retieve the attachment from body or you are getting error while parsing the attachment. 
BittusBittus
Actually, i have some records data like Name, phone, billingcity in the file. I need to save/insert these records in Account object. We can do this by many other ways. But here, i need to save records into Account object when an inbound mail with this attached file is sent to Salesforce. *thanks & regards* *nanda kishore*
BittusBittus

Hello Sushil,

Did u see the requirement which i posted regarding Email service, to create records from the data present in inbound mail attachment.

i have a code and it helps to get the inbound mail attachment and can read the data in the attachment. It is not givng any error, but am not able to create records from the data present n the attachment.

here is the code:-

global class ContactfromEmail implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

    Contact contact = new Contact();
    contact.FirstName = email.fromname.substring(0,email.fromname.indexOf(' '));
    contact.LastName = email.fromname.substring(email.fromname.indexOf(' '));
    contact.Email = envelope.fromAddress;
    insert contact;

    System.debug('====> Created contact '+contact.Id);

    if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
      for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
        Attachment attachment = new Attachment();
        // attach to the newly created contact record
        attachment.ParentId = contact.Id;
        attachment.Name = email.binaryAttachments[i].filename;
        attachment.Body = email.binaryAttachments[i].body;
        insert attachment;
      }
    }

    return result;

  }

}
Kristopher EstradaKristopher Estrada
Hi-
We are migrating to Lightning and will be using Files not Attatments on a custom object. Will the above code work, replacing attachment with file?
Thanks! 
VIKAS SRIVASTVAVIKAS SRIVASTVA
hi,bittus
did u get the solution?
VIKAS SRIVASTVAVIKAS SRIVASTVA
if yes plz rply asap.