Newer Version Available
getRecordIdFromEmail(subject, textBody, htmlBody)
Signature
public static Id getRecordIdFromEmail(String subject, String textBody, String htmlBody)
Parameters
Usage
Requires Lightning threading to be enabled in Email-to-Case.
When you send emails with threading tokens embedded in the email subject, the email body, or in both the subject and body, most email clients quote the email body and maintain the email subject in a response. This method finds a corresponding record that matches the embedded threading token in a response.
Typically this method is used in Email Services so that you can provide your own handling of inbound emails using Apex code.
Example
If you implement header-based threading in your Email Services currently, we recommend that you use Lightning threading, which combines token-based threading and header-based threading. For header-based threading to continue to work, store emails as EmailMessage records with the MessagedIdentifier field set properly. With Lightning threading, you can use threading tokens as the primary threading method and rely on header-based threading as a fallback, or vice versa.
In this example, we rely on threading tokens and use header-based threading as a fallback.