Stack Exchange
SingleEmailMessage InReplyTo Method does not append the selected EmailMessage
I would like to reply to a specific EmailMessage using Apex. According to the SingleEmailMessage Documentation, I need to use InReplyTo method. I already added the MessageIdentifier as the parameter. The email is sent. However, it does not append the original Email that I select via MessageIdentifier.
I found little to no explanation on how 'InReplyTo' works. How do I resolve this?
RELEVANT CODE:
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setWhatId(o.Id);
email.setToAddresses(EmailIds);
email.setPlainTextBody('Test Reply Email');
email.setSubject('Email Subject');
email.setSaveAsActivity(true);
email.setInReplyTo(otherEmail.MessageIdentifier);
//content of otherEmail.MessageIdentifier: <Kcykj000000000000000000000000000000000000000000000RENWXE00bJtoJ8T9QjGapax60_qEvA@sfdc.net>
if(Attachments.size()>0){
    email.setFileAttachments(Attachments);
}
mails.Add(email);
try{
    Messaging.SendEmailResult[] results = Messaging.sendEmail(email);
}catch(Exception e){
    System.debug(e.getMessage() + e.getStackTraceString());
}


According to the documentation that you linked, you should use IDs:

Contains one or more parent email message IDs

So change this line:
email.setInReplyTo(otherEmail.MessageIdentifier);

to use the Id instead:
email.setInReplyTo(otherEmail.Id);


No. It needs to be the "Message ID" (API: MessageIdentifier), not the "Email Message ID" (API: Id). If you use Id, you will get error SendEmail failed. First exception on row 0; first error: INVALID_MESSAGE_ID_REFERENCE, In-Reply-To header is not valid.: [In-Reply-To, 02s7Y000004afp3QAA]
