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.


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


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


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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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