HomeHow ToUncategorizedHow to Send Desktop Notifications in Salesforce Flow

How to Send Desktop Notifications in Salesforce Flow

The requirement: when an Opportunity advances to a specific stage, send an email alert and an in-app Salesforce alert. Sending the email alert was easy – been doing that for over a decade – sending the in-app Salesforce alert was new to me. Here are the steps to send an in-app Desktop alert in Salesforce – nd alert that looks like this:

The first step is to create your notification – that’s under Salesforce >> Setup >> Custom Notifications:

For this example I just created a Desktop alert. Once you’ve created your Notification, you’ll need the ID of this notification. To get this, open Developer Console and run this Query:

Select Id,CustomNotifTypeName from CustomNotificationType

That query will return Notification Names and IDs – copy the ID of the Notification you want to use. Create your Flow with the necessary business logic – in my case there were specific users this alert needed to go to. In order to get the users the alert should go to you have to query the user object for those users:

It’s important that the Users are Active or the alert will fail when it attempts to alert inactive users. This next step was hard for me – you then need to create a Collection Variable of Type = ‘Text’ that can store multiple values:

This is where we’ll add the List of User IDs that should get the notification. So after the Query to Get Users, we need to Loop over the Users:

And Looping over the Users, for each User, add their User ID to this List:

This part is key because this defines who the Alert will be shown for – and the Alert Action requires data in this specific format in order to send the Alert. With the List of Users you want to send the Alert To, next define the Notification Action:

Here’s how these boxes are populated:

  • Custom Notification Type ID: add in the ID of the Custom Notification created and queried at the start.
  • Notification Body: you can create a Text Template (and you can create it right in that screen) of the Notification Body – the text you want to show in the Alert.
  • Notification Title: similar to the above, you create a Text Template of what you want the Title of the Notification to be
  • Recipient IDs: this is where you add the List of User IDs created above. This has to be a List of Text variables, the Flow will reject anything else.

With those values added I could save this Notification and test it – and debugging worked. However, when I actually ran the Flow with real records, I got an error. One additional value is required in the Notification:

The Target ID – in my case I used the ‘Record ID’ of the record triggering the event. The Target ID will be where the user is routed to if they click the alert. So if a user gets this alert – that an Opportunity changed to a certain Stage – they can click the alert and will be routed to the record.

That’s it – kind of a cool feature in Salesforce to post ‘alerts’ about things without the need to send emails or slacks all the time.