You need to sign in to do that
Don't have an account?
Andegosu
How to set reference of EmailMessage to Case using setReferences()?
With the new update of email-to-case threading behavior, Thread-Id field is being deprecated: https://releasenotes.docs.salesforce.com/en-us/winter21/release-notes/rn_email_to_case.htm
I have an apex class that sends out an auto-response to contacts in a case based on a integration to a customer portal.
I added the thread-id before from the case before but now when this doesn't work I need to set header info so when a contact responds to the auto-response the response is added to the case, and doesn't create a new case according to this new email-to-case behavior.
I have tried using the setReferences() on Messaging.SingleEmailMessage to set a reference to the case, but I can't find proper documentation of how to set the reference, I just need a reference to the case so the response gets inserted correctly.
I have an apex class that sends out an auto-response to contacts in a case based on a integration to a customer portal.
I added the thread-id before from the case before but now when this doesn't work I need to set header info so when a contact responds to the auto-response the response is added to the case, and doesn't create a new case according to this new email-to-case behavior.
I have tried using the setReferences() on Messaging.SingleEmailMessage to set a reference to the case, but I can't find proper documentation of how to set the reference, I just need a reference to the case so the response gets inserted correctly.
You will need to write some code to generate the unique thread reference and pass the value into the method
If you try using ef:_00D0EDm2o._5000E978zj:ref you might get the error INVALID_MESSAGE_ID_REFERENCE, References header is not valid.
You will see this error because the reference should contain the parent emails' References and message IDs, and possibly the In-Reply-To fields. It has to be in proper format fpr example <19951223192543.3034.qmail@silverton.berkeley.edu> ( <> is not necessary to add to message id)
References can contain multiple Message-ID with space between them.
A Message-ID is like this: <19951223192543.3034.qmail@silverton.berkeley.edu>
Mail address encoded between <>
Reference: <19951223192543.3034.qmail@silverton.berkeley.edu> <1995134343492543.3034.qmail@silverton.berkeley.edu>
The below document can be useful to understand this:
https://cr.yp.to/immhf/thread.html
SingleEmailMessage Methods | Apex Reference Guide | Salesforce Developers
Were you able to figure out how to set the Message-ID when sending outbound emails with Apex?
Did that work for you?
@Andegosu, Thanks for the solution. Its working fine in my usecase where I already have an email message associated to the case and I am sending the email through apex for the subsequent emaill. Now user can reply to the email notification which is successfully adding back to the parent case instead of new case.
Your solution to add the email headers from earlier messages is working as expected.