Reputation: 1
I have enabled email-to-case in my org and followed steps below.
Step1: customer sent an email for the routing address, and case is getting created in Salesforce
Step2: when the salesforce user responds to the email from case quick action then it is going to customer and I can see both the step1 thread and step2 information in the quick action.
Till here everything is as excepted.
Till step3 results
I have enabled the thread details in email-to-case settings.
Insert email threading token in email subject and insert email threading token in email body.
Excepted result: when customer is responding to the reply email I should be able to create new case which will have reference_case_details__c (lookup to case) and populate the old case record into reference_case_details__c.
For populating the old values I have written the trigger which is stated below, but some how this is not working, can anyone please suggest me the appropriate changes to be done.
Code:
trigger MI_EmailMessageTrigger on EmailMessage (after insert) {
string fetchString = 'ReferenceID::';
string pastCaseNum = '';
for(EmailMessage em: Trigger.New){
if(em.TextBody != null && em.TextBody.contains(fetchString) && em.Incoming && em.ParentId != null){
List<String> words = em.TextBody.split(' ');
for (Integer i = 0; i < words.size(); i++) {
if (words.get(i).equals(fetchString)) {
if (i < words.size() - 1) {
pastCaseNum = words.get(i + 1);
if(pastCaseNum != null){
break;
}
}
}
}
for(case cs: [SELECT id,Reference_Case__c,description from case where id =:em.ParentId]){
cs.Reference_Case__c = pastCaseNum;
/update cs;
}
}
}
}
Tried with all the settings to be checked for creating new case and for the trigger part have created new EmailMessage record from anonymous window and tired to debug
Upvotes: 0
Views: 184