+ Start a Discussion
Krish NKrish N 

Parse email subject to grab first two values

I'm using Apex Email services to create cases. The email subject contains the account name on which, the case has to be created. The first two values of the subject is the account name, How do I extract it from the email subject using strings. Here's how it looks like:

Email Subject: Account P642484 2520 E Avenue S, Work Order 49878979 has a new note. In this subject, Account P642484 is the account name and I want to grab it to use it in my SOQL query. How do I do that?
Best Answer chosen by Krish N
SandhyaSandhya (Salesforce Developers) 

You may try below code 
String[] bodyParts = email.plainTextBody.split('\n');

the body parts will be a array of strings,each string will be the data from a line that you have in body of email.

once you get the lines, then you can split() on ':' to get a 2 element array for each line. Element [0] is the label, element [1] is the text.

Refer below link.

   Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
Best Regards