We recently switched to salesforce service cloud, and have some trouble getting all of our customer service emails routed/threaded correctly.

In particular is an email thats sent from our codebase (rails) to a customer and at least one other contact, we cc ourselves so saleforce can be involved in the communication, but this does't thread correctly.

Essentially I need a case/thread_id before I send this email, or I need to send this email from saleforce itself so starts out with a thread_id (ref:) in the subject/email. Id rather the former (create case/get ref thread id programmatically) because there could be 1 or many cc's involved in this email and that sounds increasingly more difficult.

Im trying to read the very verbose docs around the case API's and it feels super fragmented trying to understand if either of those use cases are possible, any pointers to resources, soap or restful wold be super helpful!


2 Answers 2



We took reference from this post - http://theblogreaders.com/generating-salesforce-case-thread-id-using-apex-class/ - for a similar use case where we wanted to generate thread id to be able to send emails from outside of salesforce.

Hope this helps or at least gives you the right direction.

Best, Vishal


It seems there is out of the box method available now to generated the formatted thread ID through apex. It worked for me!

Please try with : EmailMessages.getFormattedThreadingToken(caseId)

You may store this in custom field also to use in any outbound email or through external system also.

Please refer to this apex reference guide: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_System_EmailMessages_getFormattedThreadingToken.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .