Newer Version Available
getFormattedThreadingToken(recordId)
Returns an email threading token that’s formatted with the correct
prefix and suffix. This token can be embedded in an outbound email body, email subject, or
both the body and subject. When users reply to the email, threading tokens can be used to
attach responses to a record, such as a Case record in Email-to-Case.
Signature
public static Id getFormattedThreadingToken(Id recordId)
Parameters
- recordId
- Type:Id
- The record ID associated with the threading token. Only Case record IDs are supported.
Return Value
Type: String
The returned value is a formatted string that includes a prefix and suffix, for
example:
Usage
Requires Lightning threading to be enabled in Email-to-Case.
When sending emails in Apex, use the returned string to match emails to a record, such as a Case record, that’s associated with the email thread. Embed the formatted token in the body or subject of outgoing emails. To find the corresponding record ID in incoming emails, use EmailMessages.getRecordIdFromEmail(subject, textBody, htmlBody).
Example
In this sample, we send an email with a threading token so that the email and any responses are associated with the related case.