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
Itayb34Itayb34 

Parse Email body into custom object

Hello, I would like parse an inbound email into a custom object (Training__c) and its fields. I was able to create the record, I need some help in "translating" the email body into fields (the needed fields appear in the code..).

I tried using substring below, but got an error that prevented the record insert..

 

Class:

 

global class ProcessTraining implements Messaging.InboundEmailHandler {
 
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {
 
    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();


   String[] emailBody = email.plainTextBody.split('\n', 0);
String Numberofcertificationattempts = emailBody[0].substring(0);

 Training__c em= new Training__c (Message__c = email.plainTextBody);
 
em.Number_of_certification_attempts__c = decimal.valueof(Numberofcertificationattempts);
em.Date_training_completed__c = 
em.Total_time_in_training_course__c = 
em.Training_certification_score__c =
    
    insert em;
    


   return result;

 

Email:

Email sent from the Demo version of the Email Reporting Widget:

***************************************************************************
*********              Project and access information               *******
***************************************************************************

Student name: 
Project name: 
Date completed: 6/12/2013
Time completed: 12:02:32
Total time spent in course: 

***************************************************************************
*********                 Quizzing Information                      *******
***************************************************************************

Quiz score in percent: 
Total Points Scored: 10
Total Points Available: 10
Points needed for a pass: 8

Number of quiz attempts: 1
Total number of quiz questions: 1
Total number of correct answers: 1
Total number of unanswered questions: 1

 

 

Thanks!

 

Itay

Ashish_SFDCAshish_SFDC

Hi Itay,

Parsing email body is not one of the best practice but you may try catching each line in an array and catching the field value from the Character location.
Please see the related post below for more info.
http://boards.developerforce.com/t5/Apex-Code-Development/Parsing-email-body-to-populate-case-fields/td-p/175017


Regards,
Ashish, Salesforce.com
If this post answers your question, please mark this post as Solved.