---
schema_version: "1"
id: 7a432cc4dcaec0fd40964f1d437e5ab232dea29369953945d86e9abb1a63d5d2
title: Email-to-Case Threading
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/service/264-0-0/support_email_to_case_threading.md
canonical_url: https://help.salesforce.com/s/articleView?id=service.support_email_to_case_threading.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 26d33669053e7c916975093b99f19a0c06fc2e9275095bacc97d1b20893540c9
description: Email threading ensures that outgoing emails and incoming responses related to a customer inquiry are associated with the same case in Salesforce. Threaded emails appear in the case feed so service reps and supervisors can quickly grasp an inquiry’s history and status.
products:
  - Service Cloud
  - Digital Engagement
release: "264"
---
# Email-to-Case Threading

Email threading ensures that outgoing emails and incoming responses related to a customer inquiry are associated with the same case in Salesforce. Threaded emails appear in the case feed so service reps and supervisors can quickly grasp an inquiry’s history and status.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col style="width:100%"></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=service.customizesupport_email_editions.htm&amp;release=264.0.0&amp;type=5" title="Learn about the Salesforce editions and user interfaces that support Email-to-Case.">View supported editions</a>.</td></tr></tbody></table>

Email-to-Case previously used a threading method called Ref ID threading, and later added support for an alternative method called email header-based threading. Email-to-Case is now transitioning to Lightning threading, a more secure method that combines header-based and token-based threading.

![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/images/icon_important.png)

Important We strongly recommend that you switch to Lightning threading by enabling the Disable Ref ID and Switch to Lightning Threading release update. Ref ID threading is in maintenance-only mode, and can’t be used with header-based or Lightning threading. For help, see [Update to Lightning Threading for Email-to-Case](https://help.salesforce.com/s/articleView?id=service.customizesupport_email_thread_update.htm&release=264.0.0&type=5 "Lightning threading is a secure method used by Email-to-Case to associate emails with related cases. To switch to Lightning threading from Ref ID threading, you’ll enable a release update, update your Email-to-Case settings, and update any email templates and custom code that rely on older threading methods.").

## Find Your Current Threading Method

If you’re not sure which threading method you’re using, go to the Email-to-Case page in Setup.

- If you see settings named **Insert thread ID in the email subject** and **Insert thread ID in the email body**, you’re using Ref ID threading. Enable the release update to switch to Lightning threading.
- If you don’t see those settings, you’re using Lightning threading or it’s available in your org. To get the full case-matching benefits of Lightning threading, we recommend:
    - Select **Insert email threading token in email subject**, **Insert email threading token in email body**, or both: This turns on the token-based component of Lightning threading. Verify that the settings you see contain the word “token”.
    - Select **Use email headers for threading**: This turns on the header-based component of Lightning threading.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:20%">
          <col style="width:40%">
          <col style="width:40%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d93908e120">Threading Approach</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d93908e123">Key Characteristics</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d93908e126">Availability</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Threading Approach" class="slds-cell-wrap" style="vertical-align:top;" headers="d93908e120 ">Lightning threading (recommended) </td>

            <td data-label="Key Characteristics" class="slds-cell-wrap" style="vertical-align:top;" headers="d93908e123 "><a name="support_email_to_case_threading__ul_upj_xph_g2c"><!-- --></a>
              <ul id="support_email_to_case_threading__ul_upj_xph_g2c">
                <li>Combines token-based and email header-based threading.</li>

                <li>Incoming emails are matched to cases using a 23-character token in the email
                  subject or body. If no matching case is found, email header-based threading is
                  used.</li>

                <li>Applies to emails sent from the case feed email composer in Lightning
                  Experience.</li>

              </ul>
            </td>

            <td data-label="Availability" class="slds-cell-wrap" style="vertical-align:top;" headers="d93908e126 ">
              <p>Auto-enabled in orgs created in Spring ’23 or later, and supported only in
                Lightning Experience.</p>
              <p style="margin-bottom:0;">Lightning threading is backwards compatible: When you switch
                from Ref ID to Lightning threading, emails continue to thread to cases using email
                headers that were previously stored.</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Threading Approach" class="slds-cell-wrap" style="vertical-align:top;" headers="d93908e120 ">Email header-based threading</td>

            <td data-label="Key Characteristics" class="slds-cell-wrap" style="vertical-align:top;" headers="d93908e123 "><a name="support_email_to_case_threading__ul_vpj_xph_g2c"><!-- --></a>
              <ul id="support_email_to_case_threading__ul_vpj_xph_g2c">
                <li>Incoming emails are matched to cases using a Message-ID contained in the
                  In-Reply-To or References headers. Salesforce looks for an existing EmailMessage
                  record whose MessageIdentifier field matches the Message-ID.</li>

                <li>Used if Lightning threading is enabled and no matching case is found using
                  token-based threading. </li>

              </ul>
            </td>

            <td data-label="Availability" class="slds-cell-wrap" style="vertical-align:top;" headers="d93908e126 ">Auto-enabled in orgs created in Winter ’21 through Winter ’23. In orgs created
              in Spring ’23 or later, it’s included as part of Lightning threading.</td>

          </tr>
          <tr class="">
            <td data-label="Threading Approach" class="slds-cell-wrap" style="vertical-align:top;" headers="d93908e120 ">Ref ID threading</td>

            <td data-label="Key Characteristics" class="slds-cell-wrap" style="vertical-align:top;" headers="d93908e123 "><a name="support_email_to_case_threading__ul_wpj_xph_g2c"><!-- --></a>
              <ul id="support_email_to_case_threading__ul_wpj_xph_g2c">
                <li>Incoming emails are matched to cases using a Ref ID string in the subject or
                  body. Outgoing emails sent from the case feed email composer contain a Ref
                  ID.</li>

                <li>Responses to case email alerts and to emails sent via Apex aren’t added to
                  cases unless you implement a custom solution.</li>

              </ul>
            </td>

            <td data-label="Availability" class="slds-cell-wrap" style="vertical-align:top;" headers="d93908e126 ">
              <p>No longer recommended; switch to Lightning threading. After you switch to
                Lightning threading, outgoing emails contain a token instead of a Ref ID.</p>
              <p style="margin-bottom:0;">If you
                switch from Lightning threading back to Ref ID threading, emails may not be
                correctly threaded. </p>
            </td>

          </tr>
        </tbody>
      </table>

## How Lightning Threading Works

In Salesforce, each incoming and outgoing email sent by a person or AI agent is represented by an EmailMessage record. To link incoming emails to related cases, Email-to-Case searches EmailMessage records for matching threading information. Outgoing emails sent from the case feed are automatically linked to the case.

Lightning threading relies on tokens in the email subject and body as the primary threading method, and uses header-based threading as a fallback. The tokens and email header information serve as signposts that point Email-to-Case toward any related emails in Salesforce.

![Graphic showing sequence of events when Salesforce attempts to thread incoming emails](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support_channels-264-0-0-production-enus/f3c4b3d2-ff86-4f7c-9fe2-3d8b23d35109/support_channels/images/email/threading_graphic.png)

Email threading tokens are a unique 23-character string formatted with a prefix and suffix. Here’s an example: `thread::pp5XPGfmNf2hRZdRCWnrohc::`. When Lightning threading is in use, threading tokens are added to the email subject, body, or both of all outgoing case emails. Threading tokens and Ref IDs aren’t shown in the case feed, but reps can see them on the email message detail page or in the composer.

When a customer sends your business an email, Email-To-Case follows these steps to try to find a related case:

- First, Email-to-Case looks for an EmailMessage record in Salesforce whose token matches the token in the incoming email’s subject or body. If a matching email is found, the customer’s email is linked to the matching email’s related case.
- If Email-to-Case can’t find a matching email thread using tokens, it switches to header-based threading.
    - Email-to-Case searches for an EmailMessage in Salesforce whose Message-ID, stored in the MessageIdentifier field, appears in the incoming email's In-Reply-To header. As of Summer ’20, Salesforce automatically saves the Message-ID of all Email-to-Case emails sent from the case feed. If a match is found, the customer’s email is linked to the matching EmailMessage’s related case.
    - If no match is found, Email-to-Case uses the References header to search for a match. The References header is a list of Message-IDs from previous emails in a thread. If one or more Message-IDs in References matches an EmailMessage record’s Message-ID, the customer’s email is linked to the most recently created matching EmailMessage's related case.
- If no match is found using the In-Reply-To or References headers, Email-to-Case checks the incoming email for an Outlook-specific header called Thread-Index. Thread-Index values are hexadecimal coded when stored to allow for faster database searches. The first 22 bytes of this header uniquely identify the thread. A Thread-Index header on the incoming email longer than 22 bytes means it’s a reply email. In that case, Email-to-Case looks for matching information in the ClientThreadIdentifier field in EmailMessage records. If a match is found, the customer’s reply email is linked to the related case. Thread-Index is stored in ClientThreadIdentifier only when it’s 22 bytes in length, meaning it’s the first email in the thread. This storage policy minimizes the chances of unrelated emails threading to the same case.
- If Email-to-Case still can’t find an email with matching information, a new case is created to track the customer’s inquiry.

## Apex Support for Threading

In Apex code, you can take advantage of Lightning threading in Email-to-Case.

- For incoming emails, include the [EmailMessages.getRecordIdFromEmail](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_System_EmailMessages_getRecordIdFromEmail.htm) or [Cases.getCaseIdFromEmailHeaders](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_System_Cases_getCaseIdFromEmailHeaders.htm) methods in your custom email services to retrieve case identifiers from email tokens or email headers, respectively. These methods replace the deprecated getCaseIdFromEmailThreadId method.
- For outgoing emails, use the [EmailMessages.getFormattedThreadingToken](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_System_EmailMessages_getFormattedThreadingToken.htm) or [Cases.generateThreadingMessageId](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_System_Cases_generateThreadingMessageId.htm) method to include a threading token or email header-based threading information, respectively, in outgoing emails. Email-to-Case can then thread replies to the right cases.

## Learn More

If you like learning via audio, this podcast-style audio tour explains how email threading works in Salesforce and how to upgrade to Lightning threading. The audio features an AI-generated conversation between two Salesforce admins.

- **[Email-to-Case Threading Limitations & Considerations](https://help.salesforce.com/s/articleView?id=service.email_threading_limitations.htm&release=264.0.0&type=5)**  
    Review limitations and considerations related to email threading in Email-to-Case.
- **[Threading Automated Case Emails](https://help.salesforce.com/s/articleView?id=service.customizesupport_email_thread_automated.htm&release=264.0.0&type=5)**  
    When Lightning threading is enabled, the case feed shows case emails sent by service reps or AI agents, and incoming responses to those emails. You can also configure Email-to-Case so the case feed includes certain automated case emails, such as emails sent by auto-response rules or Apex.
- **[Update to Lightning Threading for Email-to-Case](https://help.salesforce.com/s/articleView?id=service.customizesupport_email_thread_update.htm&release=264.0.0&type=5)**  
    Lightning threading is a secure method used by Email-to-Case to associate emails with related cases. To switch to Lightning threading from Ref ID threading, you’ll enable a release update, update your Email-to-Case settings, and update any email templates and custom code that rely on older threading methods.

#### See Also

- [Knowledge Article: Disable Ref ID and Switch to Lightning Threading](https://help.salesforce.com/s/articleView?id=000355168&type=1&mode=1&language=en_US)
- [Email Services](https://help.salesforce.com/s/articleView?id=platform.code_email_services.htm&type=5&language=en_US)