I would like Salesforce to create some records for me based on data that is incoming in an email's CSV file attachment.
I've investigated the Email Services functionality, and set up an address, where if I send an email with a file attached, an Apex code runs.
Now in this Apex code I would like to be able to verify the CSV file attachment, and if it's the correct type, go thru it, and create a custom record for each of the lines in the CSV file.
Thinking about it, I came down to the 2 following solutions, however, I'm unaware of the limitations of each method, so I would be incredibly grateful for any guidance!
VERSION 1:
Inbound Email Service class takes care of all the CSV parsing, and record creating. Could there be any limits here on how much data can an Inbound Email Service class process?
or
VERSION 2:
Inbound Email Service class simply just creates a "JOB" type custom record where it also saves the attached CSV file from the email. (Could there be a size limit here?)
Then I have a separate process running on this JOB object type (which start upon creation), and I parse the CSV file at this time.
Any help is appreciated!
Later edit: forgot to mention, that the maximum size of the CSV is under 100 KB, and under 500 rows.
Best Answer
So the main limitation you will find here is the amount of Heap Space required of transforming your CSV into a workable Apex Type to parse through. That said as long as the combination of Rows and Columns in your CSV doesn't exceed that limit, either approach is fine. I actually did this as an AppExchange app a while ago and used the first approach.
EDIT (in response to your comment)
So I guess the first thing is just make sure when you convert your attachment from a
blob
to astring
that it is actually right. Here is a sample Inbound Email parser:Here is what my
testAtt.csv
looks like:And here is what my
debug()
statement prints out:From there you should be able to take that
string
and put it through any CSV parser to give you a two dimensional array to parse through.Sidenote; here are the settings for my Email Service, note the "Convert Text Attachments to Binary Attachments":