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.
Step3: Now when the customer is responding to the same email , I should be able to create new Case in Salesforce instead I can see that the Step3 response related information in the Parent Case Activity.
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
manjula srinivas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.