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
StaciStaci 

parse an email

I need to be able to parse the body of an external email to create a record in one of our custom objects. 

 

I don't want the entire body in one field.  The current email has fields like DESCRIPTION, RISK, ETC

 

Is there a way to "find" these headers somehow in the email and pop the info into certain field in SF?

 

Thanks!

Jeff MayJeff May

Where is this email body located?  If you are writing an email service, you have the entire body in one field, If you are trying to pull info out of the Description field from a Case (for instance), you'll have to write a trigger to get the contents and parse out what you need into other Case fields.

StaciStaci

Hi JeffM

I have an email service set up and an apex class started to recieve the email and sort out the to/from/subject part, but when I got to the part in the instructions about the body it said you can put it in a note field.  I need to be able to separate out the body of the email we get into different fields.

 

How would I write that trigger? Do you have an example?

Jeff MayJeff May

In your email service class, you can use the properties of the Messaging.InboundEmail to get the plainTextbody as a string, then parse the string as needed.

Shivanath DevnarayananShivanath Devnarayanan

You can parse through the email body as required. But warning it will not be foolproof.

 

Assumptions

1) You have a fixed pattern for the incoming email 

2) You are willing to custom code and parse through the string

 

 

global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                       Messaging.InboundEnvelope env){
 
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
  
    String myPlainText= '';
    
    // Add the email plain text into the local variable 
    myPlainText = email.plainTextBody;
  

// once you've the body 
assuming your email may look like this

Description: blah.. blah 
Risk : 5

 you could then use String Methods : http://goo.gl/c7NY3 

to parse away all the details you require.

 

Thanks

 

RockDeveloperRockDeveloper

go to Salesforce.com help section and find the Messaging.InboundEmailService