Generating Salesforce Case Thread Id Using Apex Class

Case Thread ID:
“Case Thread_Id” Use for Preventing New Cases and Only Allowing Case Updates via Email.

Case Thread ID contatins the combination of Organization Id and Case ID.

Example: VALID

Code Example:

String caseId = ‘500c00000024Dru’;
string Case_ThreadID = ‘_’  + UserInfo.getOrganizationId().left(4)  + ‘0’  + UserInfo.getOrganizationId().mid(11,4) + ‘._’  + caseId.left(4) + ‘0’  + caseId.mid(10,5) + ”;
system.debug(‘CASE THREADID:::’ Case_ThreadID);

Generating Salesforce Case ID with the help of Case Thread Id Using Apex Class:

String case_threadId = ‘_00Dc0LQjo._500c024Dru’;
Id CaseID = Cases.getCaseIdFromEmailThreadId(case_threadId);
system.debug(‘CASE ID:::’ CaseID);

We can get the 18 digit case id.

Generating Salesforce Case Thread ID Using Custom Formula Field:

Create a New Custom Formula field in Case Object with Return type as Text and paste it below statement in Formula Text area section

“ref:_00D”&MID(Id,4,1)&RIGHT($Organization.Id, 4) &”.”& LEFT(Id,4)&RIGHT(Id,5)&”:ref”

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

Your email address will not be published. Required fields are marked *