Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

When I send an email to a recipient from a case within Salesforce, the recipient's email subject contains a unique code generated by Salesforce. This code is used by Salesforce then for routing the response back to the case. Is there a way to get the unique reference code from within Salesforce (on the case object record), i.e., is there a field that stores this code? I would like to be able to attach emails to cases using this code.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

This information is not stored in a field but it can easily be calculated in a formula or in Apex.

Formula:

ref:_00D"&MID(Id,4,1)&"0"&RIGHT($Organization.Id, 4) &"._"& LEFT(Id,4)&"0"&RIGHT(Id,5) &":ref

Apex:

public static String ThreadId(String caseid)
    {

        string Case_ThreadID = '_' + UserInfo.getOrganizationId().left(4) + '0' ;
        Case_ThreadID = Case_ThreadID + UserInfo.getOrganizationId().mid(11,4) + '._';
        Case_ThreadID = Case_ThreadID + caseid.left(4) + '0' + caseId.mid(10,5);

        return Case_ThreadID;
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.