function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KD123456KD123456 

Require Help with Single Email Messaging

The requirement is

 

  1. Send notification emails to a particular email address whenever there is an email activity in a case. The notification should contain the email body.
  2. The notification emails should contain the attachments that were part of the email that triggered the notification.
  3. The notification emails of case should form a conversation thread in gmail (the specified email address is gmail)

 

I am able to complete the first 2 requirements, but the 3rd one is causing troubles. It works partially though. With all that I have heard Gmail uses the Subject line to group emails into a conversation thread. I have a constant Subject but still the notification emails create new conversation threads for each new day.

 

Example

Day 1 – there are 8 email activities in the case 1 and there are 2 email activities in case 2. The apex code sends 8 notifications related to case 1 that form a conversation thread and 2 notifications for case 2 that form another conversation thread. (this is correct)

Day 2 – there are 3 email activities in case 1 and there are 4 email activities in case 2. The apex code sends 3 notifications related to case 1 but this forms a new conversation thread and is not part of the same conversation thread created on day 1.

 

How can I form a single thread for each case instead of single thread of each case on each day?

 

I tried using the setInReplyTo and setReferences but got errors and the notification was not sent. Will this help in the threading problem, what are the other options?

 

Thanks

KD

 

Best Answer chosen by Admin (Salesforce Developers) 
thomastthomast

The In-Reply-To: email header should be a single Message-ID, per the RFC that defines Internet messaging

 

Message-IDs are intended to be globally unique, and take the form:

<unique-local-message-identifier@fully.qualified.domain.name>

 

For example, here's the Message-ID header from a VF template message I got today:

 

Message-ID: <21940225.44359.1296247408924.JavaMail.sfdc@na2-app3-13-sjl.ops.sfdc.net>

 

So a reply to that message would have the following header (in order to thread correctly):

 

In-Reply-To: <21940225.44359.1296247408924.JavaMail.sfdc@na2-app3-13-sjl.ops.sfdc.net>

 

So, In order to set the "In-Reply-To:" header correctly, you would need to either generate and store the Message-ID of the first message in your intended thread, or at least capture the Message-ID that Salesforce generates. It doesn't look like the email methods allow for setting the Message-ID, or the fetching of the SF-generated Message-ID. Or, if the Case is generated from an email in the first place, you could parse that Message-ID out and use it in the In-Reply-To headers.

 

I suspect, but don't know for sure, that if you generated an In-Reply-To header with a correctly-formed Message-ID for all the messages on a Case, they would thread correctly in Gmail, even if no message with that Message-ID actually exists. I'm an email nerd, not an Apex coder, so I can't give you specific code, but if I were writing it as a regular Salesforce formula, it might be:

 

"<MyForceApp." & Case.ID & "@customdomain.my.salesforce.com>"

 

Or if I wanted a unique thread per day, I could do:

"<MyForceApp." & Case.ID & "." & TEXT(TODAY()) &  "@customdomain.my.salesforce.com>"

 

Hope that helps!

 

 

All Answers

Jon Mountjoy_Jon Mountjoy_

I don't have much experience with the email system but I do know that the inReplyTo can be important. 

 

See this external blog post that seems to indicate that it's used in threading.

thomastthomast

The In-Reply-To: email header should be a single Message-ID, per the RFC that defines Internet messaging

 

Message-IDs are intended to be globally unique, and take the form:

<unique-local-message-identifier@fully.qualified.domain.name>

 

For example, here's the Message-ID header from a VF template message I got today:

 

Message-ID: <21940225.44359.1296247408924.JavaMail.sfdc@na2-app3-13-sjl.ops.sfdc.net>

 

So a reply to that message would have the following header (in order to thread correctly):

 

In-Reply-To: <21940225.44359.1296247408924.JavaMail.sfdc@na2-app3-13-sjl.ops.sfdc.net>

 

So, In order to set the "In-Reply-To:" header correctly, you would need to either generate and store the Message-ID of the first message in your intended thread, or at least capture the Message-ID that Salesforce generates. It doesn't look like the email methods allow for setting the Message-ID, or the fetching of the SF-generated Message-ID. Or, if the Case is generated from an email in the first place, you could parse that Message-ID out and use it in the In-Reply-To headers.

 

I suspect, but don't know for sure, that if you generated an In-Reply-To header with a correctly-formed Message-ID for all the messages on a Case, they would thread correctly in Gmail, even if no message with that Message-ID actually exists. I'm an email nerd, not an Apex coder, so I can't give you specific code, but if I were writing it as a regular Salesforce formula, it might be:

 

"<MyForceApp." & Case.ID & "@customdomain.my.salesforce.com>"

 

Or if I wanted a unique thread per day, I could do:

"<MyForceApp." & Case.ID & "." & TEXT(TODAY()) &  "@customdomain.my.salesforce.com>"

 

Hope that helps!

 

 

This was selected as the best answer
KD123456KD123456

Hi,

 

After much trial and error, I used the format provided by you on references instead of in-reply-to and it has worked for me. Thanks for your help.

 

KD

JonnoGJonnoG

@

Amit Yadav 9Amit Yadav 9
@KD123456 i also have have the exact same requiredment,i have been going at it for days, can you please elaborate a little what worked out for you? Its really urgent.
Thank You