Flow: Send Custom Notification Action
Sometimes the smallest new feature catches your eye, and you just want an excuse to use it. That was the situation I was in a few days ago when thinking about the new Custom Notification Builder.
My work Org is still Classic (shhh!), but I hone my Lightning skills in a personal Developer Edition with wildly over the top objects, processes and automation.
Now, I could write about the simple notification I set up in Process Builder to congratulate the user when they add a new opportunity, but that is too simple. Setting up notifications in Process Builder is as straight forward as creating a new record, i.e. if you’ve created a couple of processes already, you’ll easily work out what to do. (OK, you win – scroll down to the end of this post for bonus content on how to set this up using Process Builder!)
This post is about creating notifications in Flow, using the Send Custom Notification Action. Currently, there is very little written about the configuration of this Action, and I learnt a few things along the way that need sharing.
This is what the Action looks like in Flow:
These are the required Input Values:
- Custom Notification Type ID (required)
- Notification Body (required)
- Notification Title (required)
- Recipient IDs (required)
- Target ID (required)
- Sender ID (optional)
Straight forward yes? No, not all of them…
Let’s tackle these in order:
Custom Notification Type ID
In order to create notifications at all, you first have to create a custom Notification Type (Setup > Notification Builder > Notification Types). This consists of the Custom Notification Name, and API Name (auto-populated) and Supported Channels (Desktop, Mobile).
Once you’ve done that, you need to get the Notification Type ID. But how?
After much searching, and some help from the Trailblazer Community, I was directed to a blog by Narender Singh: How to get the ID of Custom Notification Types in Salesforce?
He explains 3 different ways to get the record ID: Developer Console; inspect the code on a Process Builder page; or Workbench. As an admin who is familiar with the Developer Console, I chose this option.
- Open Developer Console
- In bottom panel, click on Query Editor tab
- Check the “Use Tooling API” checkbox
- Type the query:
SELECT Id,CustomNotifTypeName FROM CustomNotificationType
- Click Execute
- Highlight and copy the Id in the Query Results (you may need to double-click on the Id before you can highlight it)
Notification Body (required)
This is expecting a text string, either from a variable or just typed in. Easy!
Notification Title (required)
Again, this is expecting a text string. Easy!
Recipient IDs (required)
Working out what data type this field expected proved to be the biggest test. Entering a user ID gave the error “The data type of the resource you entered isn’t compatible”. Entering a text string did the same. It wouldn’t accept a Record Variable, or a Collection Variable. So what did it want?
Enter the Answers Community, a question headed Flows: What is the correct data type for Recipient ID in Send Custom Notification Action, and an answer from the photo-less Tajinder Singh.
He explains that while looking for CustomNotificationType he found a topic which says:
Recipient IDs field expects a list of Id’s. You can create a variable with datatype text and checkbox “Allow multiple values (collection)”
So, it wants a Collection Variable, which contains a set of Strings which represent Users, Queues, or Groups, eg:
Target ID (required)
This is the Record ID of the object which is the target of the notification. For my example it is the Opportunity record which has just been created.
Sender ID (optional)
This field accepts a text string. What it actually does, however, is a mystery as even when populated the notifications looked the same, and there are no notifications appearing in the Sender’s browser.
Being able to create Custom Notifications means there is no longer a need to send a user an email or post to Chatter when a Flow or Process finishes. Notifications mean the user can receive the information within Salesforce, on their current record, via the bell icon (top right) – or via a push message on their mobile.
As with all new Salesforce features, this is version 1, and it has some issues. But rest assured, Salesforce are continuing to develop this one. In fact, my Community post (about Custom Notification Type record ID) received a comment from a Salesforce Product Manager to say:
“In Summer ’19, you’ll need to get the ID of your notification type in for use in flows. We’ve already got this addressed in Winter ’20 so you won’t need to use this workaround for too long.”
For those of you that what to replicate my notification to congratulate users when they add a new opportunity, here’s how! (Don’t forget to setup your custom Notification Type first: Setup > Notification Builder > Notification Types)
- Object: Opportunity
- Start the Process: When a record is created or edited
“I try to maintain one master Process per object so I can control the order automation runs in. Hence my process starts when the Opportunity is created or edited and I use Criteria to check for IsNew().”
- Criteria: Formula evaluates to true
- Build Formula: ISNEW()
- Immediate Actions Action Type: Send Custom Notification
You’ll need to create an Autolaunched Flow, and trigger it to fire using Process Builder. This is the same Custom Notification as Process Builder, but configured in Flow as detailed above.