There are scenarios when you need a case thread id , either in your flow or in Apex. Currently you cannot use SOQL to get the case thread id. There are some workarounds as creating a formula but they are not reliable as can be seen in comments in this idea -> Open idea: https://success.salesforce.com/ideaView?id=08730000000XvdHAAS
1) Email Template: Case_Thread_Id_Email_Template
2) Apex class: EmailUtilityClass, EmailUtilityClassTest
3) Flow: Test_Flow_for_case_thread_id
By using a combination of email template and the "Messaging" class we can generate the case thread id based on incoming case id. There is a test flow and test class included to help understand the usage.
Do you want to try in your own org ?
-
Use anonymous window to run test code:
List<EmailUtilityClass.CaseTemplate> caseTemplateList = new List<EmailUtilityClass.CaseTemplate>(); EmailUtilityClass.CaseTemplate testCase = new EmailUtilityClass.CaseTemplate(); testCase.caseId='5004100000WcHURAA3'; caseTemplateList.add(testCase); System.debug('Case thread id :'+ EmailUtilityClass.getCaseThreadID(caseTemplateList));



