Use Flows to Track Unread Emails on Cases in Salesforce

In this post we will see how to track or check Unread Emails or New Emails on Cases in Salesforce. This will help users working on Case Management or Service Cloud to keep a track of Cases on which new Emails are received from customers and needs their attention. Users can easily Check if a Case has New or Unread Email even from List Views directly using this approach. 
There are lot of custom solutions for this requirement & most common one is by using a Visualforce page embedded in a Case screen (which I have used myself earlier). But today, we will see how to achieve the same using Flows. More Power to Admins!
Track Incoming Emails on Cases in Salesforce
Track Incoming Emails on Cases Using Flows in Salesforce

How to track New Incoming Emails / Unread Emails on Cases in Salesforce?

Let's first see what is the problem in a bit detail to understand this use case.

When working on Case Management/ Service Cloud Console and using the Email to Case or Email Service Feature, keeping track of Cases which received new emails or replies from customers is a very common and popular requirement. This is mostly needed so as to meet Case closure deadlines and also to provide a good and timely response and customer care experience to customers. 
But this becomes an issue when a Service/Customer care agent/user is working on many cases in parallel (specially using list views to manage all owned cases) and starts to lose track of cases on which new email/response is received from customers. 

Today we will see a simple solution to tackle this issue to a certain extent. The Solution is not perfect but at-least gets the job done to a great extent by notifying the users in List views or record pages about a new Email on any particular Case.

Basic Requirement/Use Case: What is actually Needed? 

Users in a org work on Cases or manage their workload from List Views and monitor all their cases from different list views. They need a field of type checkbox/boolean to be marked as True/Checked when a customer replies or sends a new email on any of the cases they are working on. 

This will help them to keep a track of new Emails on Cases from List Views itself instead of relying on email notifications or Tasks which can be missed easily.

Also, they want that after they have reviewed the Case, this checkbox should be unchecked automatically so that they are able to see only the cases in list views which they haven't reviewed or have new incoming emails.

How to check if Case has New or Unread Emails in Salesforce?

We will use Flows to achieve this functionality instead of VF or code. 

Two Flows will be needed to achieve this. 

One Record-Triggered Flow on Email Message Object & a Screen Flow to be embedded on a Case Record Page in Lightning.

Before creating Flows we will need to create a new Boolean field on Case Object. 
I have named this field Unread Email and added on my Case Layout.

Thought behind this : How this will work?

Some Background: If you are not familiar with Email to Case, let me explain how it works. When an Email is sent on an Email to Case address of Salesforce, Salesforce creates a new Record of Email Message Object. The parent record of email message is a Case Record and Case is the Parent record for Email Message in Email To Case. This Email Message has all the details of the Email sent by the customer. We will utilise this in our solution as we will work on Email Message Object.

I also recommend to read more about Email-to-Case feature if you have not used it before.

Working Explanation: Whenever a new Email Message record  is created in Salesforce from an Email, we will first check if the Email is Incoming and not outgoing as Email Message record is created even for outgoing emails from Salesforce.

Also, we can check other conditions based on different use cases like checking from address or case type etc. But in my scenario I am not doing that and I will only check if an Email is incoming or not.

After this, we will update the Parent Case of the Email Message by marking the boolean field we just created "Unread Email" as True on every such Email Message record creation.

The Second Flow in our Solution, a Screen Flow (Invisible on Screen) will be placed on the Case Record Screen in Feed Tab and wherever we want to place it. I am going to place this flow on the Feed Tab/Chatter Tab because thats where the Case Owners see all the emails in my project requirement. This Flow will be hidden or invisible (we will see later how). This flow will just update the Case Boolean field "Unread Email" back to False/Unchecked whenever user opens the Activity Tab and if previously that field was checked or True. 

This way we have created a simple solution to identify which Cases needs to be reviewed by the User after an Email is received on them and once user opens the case or Activity tab we just update the field back to uncheck. 
This is not a perfect solution but this is quite close to what is needed and helps in increasing productivity and efficiency of the customer care teams working on service cloud or cases.

Note: In my scenario I will embed the Screen Flow (which is invisible) in my Activity Tab only. But it depends on org to org and project to project and it can be used anywhere depending on from where you want to trigger the Case record.

Let's See this in Action and Steps.

1. Create a After Insert Record Triggered Flow on Email Message Object

This is a very simple Trigger Flow and this is how the Flow will look like.
Use Flows to Track Incoming Emails on Cases in Salesforce
We will create a simple Record Triggered Flow which will fire after Insert of Email Message and condition is simple that Incoming = True. We are creating After Insert Flow because the Update has to be done on the related Object not the Email Message Object itself. Since, this cannot be done in a Before Update Flow we need After Update Flow.

As I mentioned, the Flow should fire only if Incoming field value = True.
How to check if Case has New or Unread Emails in Salesforce?
Create an Update Element to Update the Parent Case
Whenever this Record Triggered Flow will Fire and if we find any incoming Emails, this Flow will update the Case Record which is the Parent Record of Email Message with Unread Email = True. So we will just use an Update Element. 
Also, we will only update the parent case only if the existing value of that is False/Unchecked just to avoid unnecessary updates.

check if Case has New or Unread Emails in Salesforce?
Create Screen Flow without Navigtion


Note: Please add a Fault Connector for the Update Element so as to prevent any exceptions or loss of Email data if something goes wrong.

So, our first Flow, Record Triggered Flow on Email Message is Complete.

2. Create a Screen Flow without a header and Footer (An Invisible Screen Flow)

Now we will create our Second Flow which is an Invisible Screen Flow. By invisible we mean that it will be there but will not be seen. Special Powers ! Below is the final Flow Image. This is how the Flow will look after it's completed.

Unread Emails on Cases in Salesforce
This is also a very simple Screen Flow which will just be doing a simple Update of Case whenever it will be loaded. 

1. Create an Input Variable of type Record and object as Case.

First, we will create an Input Variable for the Flow using Manager tab and click on New Resource. 


The Input variable name is CaseRecord.

For those who are wondering why is that needed, the answer is : Since this is a Screen Flow and will be placed on a Case Record Page, we need to know which Case this Screen Flow is running on at any point of time. So for the same reason we will create a Variable and mark it as Available for Input and type will be Record as it can get all the Case Record values directly without needing to query it.

2. Create an Update Element to update the Case

Then, we will create an Update Element which will just find and update a Case if it matches our condition. 

To find our case we will be using the Id of the passed Case Record Variable. Also, we will put one more filter/condition in the Update element to check if Incoming Email field value is true or not.

Basically if this field is already false there is no point updating the case with field value as false again. 

To check the field value in Unread Email, we will get the current case's field value using the CaseRecord input variable we created in last step. And we will get case Id using the Id of the passed CaseRecord Variable. See Screenshots for more clarity.


If the value of Unread Email is True, we will just update the current case using its case Id. The Case Id can be found using CaseRecord input variable we created in last step. Just need to do {!CaseRecord.Id}


How to Create Invisible Screen Flow? 


A Screen Flow without Navigation Buttons

 

1. Create a new Screen Element on this Flow.
3. Unselect the Show Header and Show Footer option in the Configure Frame Option and Save the element.

And we are done! 

Activate the Flows and also Add this Screen Flow on Case Feed Layout or any where on the Lightning Page for example in a Tab.
Do not forget to pass input variable into the Flow from the Page by clicking the Pass Values into Flow Checkbox.

Note: Since we removed the Header and Footer, this Flow Screen is not visible to Users at any point of time.



As I mentioned, this is not a perfect Solution but it works for most part and at-least gives user a heads-up to review cases after Emails are received on the case. Let me know and share with the other readers if there is a better no code solution for this. Send your comments below or reach me on LinkedIn or Twitter.

Checkout all Flow Posts on this Blog here: https://www.accidentalcodersf.com/search/label/Salesforce%20Flow

Thanks for reading!

Join 200+ Subscribers and receive all my latest Posts directly in your Inbox.

Enter your email address:


Delivered by FeedBurner

Comments


Never Miss Latest Posts