Flows | How to Send Custom Notifications from Flow
Custom Notifications from Flows Salesforce : In this post we will see how to use or Send Custom
Notifications from Flows in Salesforce. We will combine two new and powerful features of Salesforce
i.e. Record Triggered Flows and Custom Notification Builder to make life easier for End Users
so that they are able to keep a track of important events/notifications/updates on records that they are working
on.
Salesforce Flow Custom Notifications can be
achieved by using Flow Core Action : Send Custom Notification which we will see later in this
article.
We will also see one Important Technique : How to get ID of Custom Notification Type in a Flow directly?
Don't worry if you are not familiar with the concept of Custom
Notification Id as we will see this in the article later.
How to Use Salesforce Flow to Send Custom Notifications?
In Simple words we can use a Flow Core Action : Send Custom
Notification. We will see later in Article how to use this. Let's first see an example Scenario
and Use Case.
Use Case: In
this article, I will
use a simple and a common use case where we need to Notify Case Owners
about New or Incoming Emails on Cases. Basically, Case
Owners should be able to Track any New Emails on any of the Cases they are working on directly from
their Salesforce Notification Icon. This is one of the most common requirements in Service Cloud Implementations
in Salesforce so here I am presenting one of a way to achieve this using Flow with Custom Notifications.
Note: Checkout my Previous Article about another
approach related to this same Use Case here: Use Flow to Track New Incoming Emails on Cases
Main Takeaways from this Article:
1. How to create a New Custom Notification in
Salesforce?
2. How to create a Simple Record Triggered Flow on
Email Message Object?
3. How to Use or Send Custom Notifications from
Record Triggered Flows in Salesforce?
4. How to Get Id of Custom Notification Type in
Flows?
5. How to Notify Case Owners or about New Incoming Emails on Cases using Custom Notifications?
5. How to Notify Case Owners or about New Incoming Emails on Cases using Custom Notifications?
Why and When to Use Custom Notifications in Salesforce?
1. Reduces dependency on
Notification Emails : Let's face it, nobody likes to be spammed with 100s of Emails daily. And
also there is a very huge chance that users miss some of them or don't even bother to see Email notifications
messages. Also, if we use email notifications, we need to jump screens from Email Inbox/Client to Salesforce
which is not always desirable.
2. User Friendly and Easy to Manage: No need
to switch Apps and everything resides within Salesforce Screen. No Screen Refresh Required as this
notification appears automatically on any current Salesforce Page that you are logged in.
3. Mobile Push Notifications: If using
Salesforce Mobile App, it can be used to show Push Notifications on Mobile Screens similar to other apps like
Twitter, Instagram etc.
How to Create a New Custom Notification in Salesforce using Notification Builder?
1. Go to Settings > Notification Builder >
Custom Notifications
2. Click New
3. Provide a Name and Desired Channels and Save the
record.
1. Name of the Custom Notification : "Case Email
Notification"
2. API Name/Developer Name:
"Email_Notification" - This is more Important as we are going to use this Later in our
Flow.
How to Send Custom Notifications from Salesforce Record Triggered Flows?
We are designing this Flow for our use case
where we need to Notify Case Owners about New or Incoming Emails on Cases. Let's first take a look at our Flow Design and how it will look like once
completed. See closely which different Flow Elements are used here as we will see how to use them individually
later.
I have added all the Steps later to create this
Flow. Also, I have added a Short Video at the end to show all steps in detail.
Steps to Create this Flow and Implement our Use Case (
Steps Video Also at the End)
1. Create a Record Triggered Flow on Email
Message Object
We will create an After Insert Record Triggered
Flow on Email Message Object. We need to use After Trigger and not Before Trigger because we need to send this
custom notification after the Email Message is created.
Conditions/Criteria to Fire this for After Insert
Record Triggered Flow on Email Message:
Incoming = True
This criteria is a minimum essential
criteria because we need to fire this Flow only if the Email Message was created for an Incoming Email into
Salesforce and not any outgoing Email.
Note: Email Message is created in Salesforce for
any Outgoing as well as Incoming Email into Salesforce. So that's why we use Incoming (which is a boolean
field on Email Message Object) as a way to filter only incoming Emails in Salesforce.
This is how the Element will Look Like after
this.
Before we move
forward, I want to discuss how to use Send Custom Notification Core Action in
Flows.
This is an Out
of Box Core Action Available for use in the Flows. It has many Input Values that are required in
order to configure and Use it. Let's see how to use these values and where to get their Data
from.
The Required
Input Values are as shown in Screen Shot Below:
We will go
through all of them but The most Important and Tricky one is Custom Notification Type ID. Let's first see
about the Custom Notification Type Id.
How to Get Custom Notification Type Id or ID of Custom Notification Type in Flows?
This a small gap in Salesforce Custom
Notification Builder Functionality. The Problem is that we cannot find out directly the Id of the
Custom Notification Record. And it's a problem because this ID is required in Send Custom Notification
Action from Flows or any other place in Salesforce.
For example, I
created the Custom Notification : "Case Email Notification" above in the
article. But there is now way to find/know the Id of this Custom Notification directly as we can do for other
Salesforce features like Records, Record Types, Profiles directly from the URL.
Here are some great Articles from Narender Singh : forcePanda Blog and Parul
Singh about ways to get Custom Notification Type Id in Salesforce.
1. From forcePanda: Get Custom Notification Type Id
2. From Parul Singh: https://forceblogs.com/get-id-of-custom-notification-type-in-salesforce/
But in Flows, we can get the Custom Notification
Type Id directly too. It is up to you on how you want to fetch and use this ID.
Let's see how to get this Id in a Flow directly
using a Get Record Element.
We just need to query on Object Named "Custom
Notification Type"
Condition : Developer Name = API Name of Custom
Notification which in our case is "Email_Notification" as seen earlier.
Note: As we need only one Id and it is a single
record, just use the option "Get only the First Record " in Get Element. Checkout below Screen Shot.
Important : Since we are querying on the object, we will get all the Field Values (including Custom Notification Id) of this Record after the Get Record Element and all the Field values will be stored in the Variable "Get Custom Notification Id " which is the Name of our Get Element.
Note: To fetch the Custom Notification Id field
value from this Record Variable we just need to do {!Get
_Custom_ Notification _Id.Id} which we will see later.
So, till now we
have managed to get the Id of the Custom Notification we created within The Flow. This Id we will use
directly in our Send Notification Flow Core Action later.
Now we need some
other values to provide to the Send Notification Flow Core Action. First we will see about the Recipients
Ids which is also a required Field in this Action.
3. Assign Recipient Ids using Assignment
Element
This is needed in order to determine and tell
the Flow to which users should the Custom Notifications be sent to.
Important: We can provide Recipients ID
value in Flow Action : Send Custom Notification only by using a Variable (Collection Variable) and Assigning a value to that
Variable using Assignment Element and not through hardcoding the value into the Action directly.
Basically, you can Hardcode Ids in a new
Variable using an Assignment Element but cannot hardcode directly in the Flow Action
As per Salesforce Official
Documentation :
- To add recipients, define Recipient ID as a resource. Then add values to your Recipient ID Collection Variable by adding the Assignment element to your flow.
Also, these are the valid Id types:
In our case, I am using only User Id as a Recipient
which is the Owner Id of Parent Case of the Email Message.
Note: Email Message has a Master Field
named Parent which is the Case Id on which the Email is received.
Step 1: Create New Collection Variable of Type
Text to hold Recipient Ids. (Click on Allow multiple values(collection)
We can use "Add" operator in Assignment
Element to add multiple values of same or different types. The variable name is "NotificationRecepients"
{!NotificationRecepients} as we created in Last Step. I am just using one row of Add operator
just to assign the value of the Email Message's Parent Cases's Owner Id.
Note: You can assign multiple owners or
other Ids (Example Queue Ids or Group Ids) as per the table I shared above to send this
notification to. But I am only using one in my case. To add other Ids, just use the Add operator again in
next row and provide the hardcoded Id or from any variable. We can even provide hardcoded Ids here using Add
operator.
Important: Since this is a Record
Triggered Flow, we have all the field values of the Record that Triggered this Flow in the variable
$Record. This variable is available to use anywhere in the Flow. So I am
using $Record.Parent.OwnerId here to get the Related Case Record's Owner Id
since Parent here is the Case Record on which Email Message is received.
See Image for better clarity or
representation.
So till now we have got Custom Notification Id and Recipients Ids which we need to
provide in the Flow Action as we saw earlier.
But there are Two more Required Fields left
as per the screen shot I shared earlier. They are Notification Title and Notification
Body.
We can directly hardcode or provide a message
directly in these fields but I am creating a new Formula Type Variable to show a message with Case Number
which will be dynamically populated based on the Case Number of the Parent Case Record of the Email Message
that fired this Record Triggered Flow.
ScreenShot below
I will use this same Variable for both
Notification Title and Notification Body.
Finally, Let's Configure the Flow Action : Send
Custom Notification
4. Configure Send Custom Notification Custom Action
We now have all the required Field Values to
provide to this action from the steps above.
Also, apart from this we will provide one more
value "Target ID" in this action.
This will be just the Record Id of the Email
Message that Fired this Flow {!Record.Id}
See the ScreenShot Below with all the values
provided into this Action.
Checkout a Short Video
with all the steps done above in the article for a Quick Recap and better clarity.
Flow Builder Video and Steps:
That's it! Save the Flow and Activate
it.
Now whenever an Email is received on a
Case, Case owner will be notified through a notification on the Bell Icon.
This is a very
basic example to show this capability. This powerful feature can be used in many ways to deliver custom
notification messages to Users in many different scenarios.
Hope this Helps!
Reach out to me here or on LinkedIn for any questions, issues or suggestions. Happy to Help!
Don't Miss Latest Posts : CLICK HERE TO SUBSCRIBE TO THIS BLOG
Checkout this Article for all Flow
Related Scenarios : All Flow Examples
See you next
time..
Hello
ReplyDeleteIt doesn't work!
Hi It should work. Are you getting any errors or exceptions? Please provide more details to understand the issue..
DeleteDoesnt work for Salesforce mobile app; I didnt receive the in-app notification :(
DeleteHi Vibhor,
ReplyDeleteGreat article, it worked like a charm ����
Could you please explain why you added the target Id at the end, thanks.
Thanks,, targetId represents the record Id for which notification was fired
DeleteThanks for your quick reply Vibhor.
DeleteSo if I understand it correctly, the targetId value *always* needs to be provided when using the 'send custom notification' core action for a record.
Sorry not very sure about that , you can give it a try without it if that works.
DeleteI just tried it, It looks like it needs to be added, Thanks for the help.
DeleteGreat content guys, love it.
ReplyDeleteI'm running into an:
"Error Occurred:
Custom Notification Action is not allowed"
I'm triggering from an auto-launch flow (not a triggerFlow)
Inputs
**copied the customNotifyId from workbench**
customNotifTypeId = 0ML0I0000004CGEWA2
body = {!error_notificationBody} (Test)
title = {!error_notificationTitle} (Some title)
recipientIds = {!collectionVariable_recipientId} ([0050I000009MjEFQA0])
targetId = {!recordId} (0060I00000goBqdQAE)
any thoughts on where I'm off?
Great article. Thanks for sharing.
ReplyDeleteI got a requirement when post comment received from community then send bell notification to the case owner. Please let me know is this possible.
Great Article. Thanks alot for Sharing and waiting for more wonderful flows.
ReplyDeleteGreat article, it helped me when I stuck with how to get Custom Notification Type Id and how to assign recipient IDs. Thank you very much for sharing your knowledge!
ReplyDeleteExcellent article and with lots of information. I really learned a lot here. Do share more like this.
ReplyDeleteSalesforce course in Chennai
Salesforce Online Course
Salesforce Benefits
Advantages of Salesforce
thanks, very helpful
ReplyDeleteGreat, thanks!
ReplyDeleteworked out well. thanks for the walkthrough !
ReplyDeleteHi,
ReplyDeleteHow can I send notification to the student portal but not to the salesforce application.
What should i keep in the target record, because when ever i trigger this, the notification is going to the SF notifications but not to the student portal notifications.
Thanks for the article Vibhor. Two questions:
ReplyDelete1) Can the 'Send Notification' flow core action be used when a value changes on a field such as checkbox, to the current user? ($User).
2) Will the notification appear as any standard notification, such a task assigned, on the notification icon?
Gustavo
Thanks for the article, thats was really helpful. Question, Created notification body with formula and Text type. How do I add merge fields that have text and Date/Time? I hit an error because of text type. Basically, it should like "License request date is expiring on 2/2/2022 12:00 PM".
ReplyDeleteThank you
This comment has been removed by the author.
ReplyDeleteThanks. Exactly what I am looking for... it worked like a charm
ReplyDeleteyes, true .
DeleteThanks, love you
DeleteIs there any way to clear the notifications from Notification tray
ReplyDeleteNice Explanation! How do you send custom notifications to a queue?
ReplyDeleteIt's working in Sandbox but not in UAT. Why So? Please Reply.
ReplyDeleteAgree - great steps, thank you. Helped me a lot!
ReplyDeleteWhat criteria to be followed to deploy custom notification flows for a manager to receive notifications from their subordinates in Salesforce?
ReplyDeleteFor anyone who went through this currently, it works, but the format of this guide is terrible.
ReplyDelete