Sudipta Deb

Sudipta Deb

Founder of Technical Potpourri, Co-Founder of Shrey Tech, Enterprise Cloud Architect

What is Email Threading?

Email threading in Salesforce refers to the process of automatically grouping related emails together in the context of a specific record, typically a case. This way, you can see the entire conversation history between a customer and your support team in one place.

Salesforce offers a few different methods for achieving email threading:

  • Lightning Threading (available since Spring ’23): This is the newest approach and relies on secure tokens embedded in outgoing emails. When a customer replies to an email with a token, Salesforce can match it back to the relevant case.

  • Email Header-Based Threading: This method looks for a specific email header field (Message-ID) in the “In-Reply-To” and “References” fields to link replies to the original email.
  • Ref ID-Based Threading (mostly replaced by Lightning Threading): In this older method, a reference ID was included in the email subject line to associate replies with a particular case.

Lightning threading is generally considered the most secure and reliable option, as it avoids potential issues with customers modifying the subject line and removing the Ref ID.

What is The Reason For This Change?

Emails can be securely threaded using lightning threading, which links incoming and outgoing emails to relevant cases. Email-to-Case detects corresponding cases more reliably and avoids producing a new case when a similar case already exists because Lightning threading mixes token- and header-based threading.

How is This Lightning Threading Different?

Email-to-Case in Lightning threading adds a token to the subject or content of an outgoing email on a case. Tokens are uniquely formed strings, much like Ref IDs, but they are generated in a fashion that complies with Salesforce security requirements. Email-to-Case searches for tokens in a customer’s answer to an outgoing case email in order to match the incoming message to the relevant case. Email-to-Case then reverts to header-based threading and looks for a Message-ID in the In-Reply-To and References headers if no match is found. Email-to-Case generates a new case in the event that token- and header-based threading combined are unable to find a matching case.

Email-to-Case stops inserting a Ref ID in outgoing emails and stops using Ref IDs in incoming emails for matching when you switch to Lightning threading.

When is This Change Coming To My Org?

This update was first available in Winter ’21 and is enforced in Summer ’22. This update was originally scheduled to be enforced in Winter ’22 but was postponed.

How To Enable This?

To review this update, from Setup, in the Quick Find box, enter Release Updates, and then select Release Updates. For Disable Ref ID and Transition to New Email Threading Behavior. View the update’s details and then click Enable Test Run to enable the header-based threading update.

What is The Expected Behavior?

  • Salesforce will set email preferences for threading tokens based on the corresponding Ref ID settings for email subjects and bodies as they are currently enabled. 
  • Incoming emails are matched to cases using tokens rather than Ref IDs in the email subject or body. If no matching case is found, email header-based threading is used. Outgoing emails no longer contain a Ref ID. 
  • You need to change your custom code like –
    • The Apex method getCaseIdFromEmailThreadId was deprecated. For incoming emails, include the EmailMessages.getRecordIdFromEmail or Cases.getCaseIdFromEmailHeaders methods to retrieve case identifiers from email tokens or email headers, respectively.
    • For outgoing emails, use the EmailMessages.getFormattedThreadingToken or Cases.generateThreadingMessageId methods to include a threading token or email header-based threading information, respectively, in outbound emails. Email-to-Case can then thread replies to the right cases.
  • Existing cases and emails will continue to thread using header-based. threading. No extra action is needed.


This article is not endorsed by Salesforce, Google, or any other company in any way. I shared my knowledge on this topic in this blog post. Please always refer to Official Documentation for the latest information.


Submit a Comment

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