Email-to-Flow is available on the Salesforce Appexchange.
If you haven’t taken a peek at Introducing Email-To-Flow, a low-code Email Service, please do. It won’t bite.
There are times you need/want to create a process to send a custom email. For example, you want to send a case owner an email when the status is updated to “Working”. In Flow, it’s pretty simple. Just call the Send Email action in your flow and an email is sent.
But, wait! I implemented a process with a send email action. The email is sent. But if the recipient replies, it creates a new case instead of linking to the original case. Help!
Ok, that requires a few additional steps. But don’t worry, it’s not that complicated. First, let’s explore how standard Salesforce Email-to-Case is able to link cases.
Salesforce Standard Email-to-Case
Salesforce leverages industry standard email headers. Specifically, it leverages the Message Identifier in the email header. Let’s take a look at how this occurs.
(1) A customer sends a email
A customer creates and sends an email message. The email application assignes a unique Message Identifier to email. For this example, let’s call that Message Identifier “Email1”.
(2) Email-to-Case processes the email
The Email-to-Case processes the email. A new Case (Case 123) record is created. A new Email Message record is created with the Message Identifier stamped with “Email1”.
(3) A Customer Support Representative responds
A customer support representation replies to the case via the standard case interface. Salesforce generated a unique Message Identifier for the email. For this example, let’s call that Message Identifier “SalesforceEmail1”. In additional, the email header has values set to indicate that “SalesforceEmail1” is a response to “Email1”.
(4) The Customer responds to the latest email
The customer creates a new email (“Email2”). This email sets the Message Identifier as well as setting the header to indicate this is an email thread with “Email1” and “SalesforceEmail1”.
(5) Email-to-Case processes the email.
The Email-to-Case processes the email. The process looks at the email headers thread ids (“Email1” and “SalesforceEmail1”) and attempts to find a match Email Message records for the “SalesforceEmail1 Message Identifier. A match is found for an email message record where the case is Case 123. Since a match is found, no new case is created. However, a new Email Message record is created.
By now I assume you’ve got it. The missing piece in your custom email process is the email message record. In order for Email-to-Case to link an email back to a case, a match on Message Identifier must be found.
Interesting, but what if we don’t want to create an email message record?
Fair enough. There are plenty of reasons why you may not want to create an email message record (especially if you are concerned about data storage). Don’t worry, this can still be achieved with a little trick and the help of Email-to-Flow. Let’s take a look.
(1) Generate a Message Identifier
Introducing a new apex action called “Generate Message Identifier”. The apex action creates a unique Message Identifier (with the case Id embedded). Augment your process which sends a custom email, set the In Reply To variable to the Message Identifier generated by the Apex Action. This will set the appropriate header values for the reply email.
(2) Implement Email-to-Flow with the Get ETF Message Id Apex Action
If an existing case cannot be located via the standard process (as outlined above), the “Get EFT Message Id” apex action uses the Message Identifier created in “Generate Message Identifier” to match on the case id. Since the case id is embedded in the Message Identifier, no email message record is required.
That’s it.