Introduction:
What we'll going to learn:
- How to create a New Custom Notification in Salesforce?
- How to create a record triggered flow on Task object.
- How to send Custom Notification from lightning flow?
- How to get Id of Custom Notification Type in Flows?
- How to notify Task owners on insertion of new Task records?
What are Custom Notifications:
Salesforce Custom Notifications is actually a better alternative to sending emails to users every time certain conditions are met. For e.g. If a Case is created for an Account then sending a custom notification to Account owner with Case details is better than sending an email. It is beneficial because once user clicks on the notification, he/she can directly access that particular record. Also, there is less switching between the apps.
Why Custom Notifications:
- As we know, 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.
- Custom Notifications are user friendly and screen friendly, 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.
- If using Salesforce Mobile App, it can be used to show Push Notifications on Mobile Screens similar to other apps like Twitter, Instagram etc.
Problem Statement:
Notification Body = {!Task.Subject}.
Solution Statement:
Understanding the requirement from John Smith, Rebecca Black who is UC's Application Architect suggested the solution in the form of a record triggered lightning flow for sending the custom notifications whenever a new task record is getting created. we can use a Flow Core Action : Send Custom Notification. We will see later in the post how to use this.
Now we'll going to build the solution in steps.
Step 1, Creating Custom Notification Type:
- Go to Setup > Notification Builder > Custom Notifications.
- Click New.
- Provide a Name and desired Channels and Save the record.
Custom Notification:
Label: New App Message Task.
Name: NewAppMessageTask.
Supported Channels: Desktop & Phone.
Step 3, Create a Record Triggered flow on Task object:
- Go to Setup > Process Automation > Flows.
- Click New and choose "Record -Triggered Flow".
- Choose object name "Task" and select "A record is created" option.
- Set the entry criteria "Type equals App Message AND WhatId not null" as shown below in the image.
- Choose "Actions and Related Records" option because we want to send custom notification after the Task record is created.
- Click Done.
Now before we move forward, let's discuss how to use Send Custom Notification Core Action in Flows.
The most Important and Tricky one is Custom Notification Type ID. Let's first see about the Custom Notification Type Id.
- Now Drag and Drop or Add GetRecords Element to Flow Canvas.
- Add label as "Get Custom Notification Id" and API name as "GetCustomNotificationId".
- Select "Custom Notification Type" as object name.
- Add the filter condition: DeveloperName = NewAppMessageTask.
So, till now we have managed to get the Id of the Custom Notification we created within the Flow. 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.
- Since 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 hard-coding the value into the Action directly.
- Create New Collection Variable of Type Text to hold Recipient Ids. (Click on Allow multiple values(collection).
- Use Assignment Element to add Ids to Recipient Ids Collection Variable created. We can use "Add" operator in Assignment Element to add multiple values of same or different types. The variable name is "RecepientIds" {!RecepientIds} as we created in Last Step. I am just using one row of Add operator just to assign the value of the Task Records's Owner Id.
- For Notification Body, we'll going to use Subject field of the Task record.
- Finally, Let's Configure the Flow Action : Send Custom Notification, 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} to redirect to the record detail page when user clicks on the custom notification message.
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! See you next time!
Happy Coding... 😊