Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
generateThreadingMessageId(caseId)
Signature
public static String generateThreadingMessageId(Id caseId)
Parameters
- caseId: Type: Id The case SObject ID to which replies to this email should be attached.
Return Value
Type: String
Usage
Use the returned message identifier when sending case-related emails in Apex. The returned message identifier can be used in Message-ID or References headers. However, because Salesforce doesn’t let users specify the Message-ID, we set this identifier in the References header. When users reply to the sent email, replies should be attached to the specified case.
Example
In this sample, we create an email with a message identifier so that the email and any responses can be associated with the related case.
1//Get your Case ID. Here we use a dummy ID
2ID caseId = Id.valueOf('500xx000000bpkTAAQ');
3//Create a SingleEmailMessage object
4Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
5//Set recipients and other fields
6email.setToAddresses(new String[] {'test@salesforce.com'});
7email.setPlainTextBody('Test Email Notification');
8//........... more fields ...........
9//Get the threading message identifier
10String messageId = Cases.generateThreadingMessageId(caseId);
11//Insert the message identifier into the References header
12email.setReferences(messageId);
13//Send out the email
14Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});