manjula srinivas
manjula srinivas

Reputation: 1

How to get new case(email-to-case enabled) to be created when customer respond's to an email

I have enabled email-to-case in my org and followed steps below.

Till here everything is as excepted.

Till step3 results

enter image description here

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

Answers (0)

Related Questions