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
Lorant DobrondiLorant Dobrondi 

Problems reading CSV attachment in Inbound Email Handler

Hello,

I have some issues while reading a CSV attachment of an inbound email.

I want Salesforce to listen to an email address, and process all inbound emails coming to that email address.
We will send CSV files as attachments, and I want to load that data into Leads and custom objects, however I'm having difficulties reading the CSV file.
 
if(email.textAttachments != null) {
  for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
    if (tAttachment.fileName == 'Leads-import.csv') {
      //process text attachment with CSV parser
      Blob csvBlob = Blob.valueOf(tAttachment.body);
      // Convert your csv file into a list of CSV fields
      List<List<String>> csvRecords = CSVReader.readIETFRFC4180CSVFile(csvBlob);
      import(csvRecords, 'Lead');
    }
  }
}

I implemented the above code in an Inbound Email Handler class, where nothing happens...The exact same code runs fine if I read the CSV file from a Salesforce Document/File.

I am using Marty Chang's CSV Reader implementation which can be found here: LINK (http://frombelvideres4thfloor.blogspot.com/2010/10/ietf-rfc-4180-compliant-csv-reader-for.html)

What can be the issue with the Email Handler?