Email Service to Parse CSV
Howdy. I had requirement for parsing CSV in email service, thought I should post it on my blog.So lets get started.
Step :1
First you need to create Apex class that acts as an inbound email handler which simply needs to implement the Messaging.InboundEmailHandler interface. The interface defines a single method which is handleInboundEmail.
Code Snippet:
Step 2:
Next, you need to define the email service. This establishes an email address, which you can then tie to the Apex class that you’ve just written. Define the email service by logging into your environment.
- Log into Force.com and select on Setup > App Setup > Develop > Email Services
- Select New Email Service
After setting up your email service, you’ll see something like this
That’s it. So simple isn’t it 🙂 To test your service, send email to the email address which is specified in your email service as below
After the sending email you will see Account created in your Salesforce Org (if you have setup everything correctly).
Note: This class assumes that you have three column in your excel sheet as below
You can extend the functionality as per your columns in excels. Please feel free to comment if you have any questions.
Happy Coding. Cheers!