+ Start a Discussion
Swetha B 7Swetha B 7 

Case Description parsing logic help

I have an Email to Case set up. Details coming into the body of the email. Need to Parse that Case Description Info into fields in Case. 

Email to the case is set up. The detail comes into the description: 

Contact Form

A user submitted the following information on the Contact us page

Name: XXXX

Phone: XXXX

Email: XXXX

Question/Comments: 

I have fields for each option and I need to pass the information into those fields. the format is the same every time. 

Please correct the trigger logic or provide me the solution for it.

trigger parsingemail on Case (before insert) {
 for(Case C:trigger.new){
        if(C.Subject!=Null && C.Subject.Contains('Contact Form')==True){
        if(C.Description!='' && C.Description.length()>0){
            String data=C.Description;
            C.SuppliedName=data.substringBetween('Name:', 'Phone:'); 
            C.SuppliedPhone=data.substringBetween('Phone:', 'Email:');
            C.SuppliedEmail=data.substringBetween('Email:', 'Question / Comment:');    
            update C;
            }
        }
     }
}

 
Best Answer chosen by Swetha B 7
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Swetha,

In stead of description in the third line of the code change the field to subject as below.
 
trigger CaseTrigger on Case (before insert) {
 for(Case C:trigger.new){
     if(C.subject!=Null && C.subject.Contains('Contact Form')){
        if(C.Description!='' && C.Description.length()>0){   
            String data=C.Description;
            C.SuppliedName=data.substringBetween('Name:', 'Phone:'); 
            C.SuppliedPhone=data.substringBetween('Phone:', 'Email:');
            C.SuppliedEmail=data.substringBetween('Email:', 'Question / Comment:');    
           
            }
        }
     }
}


Thanks

 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Swetha,

As per above  you are sending the Contact Form as the description but not as the subject. so we need to check the contains for the description instead of the subject.
Secondly as we are doing the before context in the trigger no need to mention the DML operation i'e Update. Please find the below piece of code.
 
trigger CaseTrigger on Case (before insert) {
 for(Case C:trigger.new){
     if(C.Description!=Null && C.Description.Contains('Contact Form')){
        if(C.Description!='' && C.Description.length()>0){   
            String data=C.Description;
            C.SuppliedName=data.substringBetween('Name:', 'Phone:'); 
            C.SuppliedPhone=data.substringBetween('Phone:', 'Email:');
            C.SuppliedEmail=data.substringBetween('Email:', 'Question / Comment:');    
           
            }
        }
     }
}
If this solution helps, please mark it as best answer.

Thanks


 
Swetha B 7Swetha B 7
Thank you very much for the response!

The subject is coming as a "Contact Form" always and on the case description coming email body with the following format like line space between each field.

Contact Form

A user submitted the following information on the Contact us page

Name: XXXX

Phone: XXXX

Email: XXXX

Question/Comments: 

Please suggest
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Swetha,

In stead of description in the third line of the code change the field to subject as below.
 
trigger CaseTrigger on Case (before insert) {
 for(Case C:trigger.new){
     if(C.subject!=Null && C.subject.Contains('Contact Form')){
        if(C.Description!='' && C.Description.length()>0){   
            String data=C.Description;
            C.SuppliedName=data.substringBetween('Name:', 'Phone:'); 
            C.SuppliedPhone=data.substringBetween('Phone:', 'Email:');
            C.SuppliedEmail=data.substringBetween('Email:', 'Question / Comment:');    
           
            }
        }
     }
}


Thanks

 
This was selected as the best answer
Swetha B 7Swetha B 7
We have a requirement to create a contact record after parsing the above trigger. Please suggest logic for this. Thank you very much!