How to send Custom Desktop/Push Notifications in Salesforce

Everyone knows that it is so important to send notifications when important events occur. For example, alert an account owner if a new support case is logged while trying to close a deal. Or, send a notification for a unique workflow built entirely with custom objects. Previously, you could send only standard notifications for use cases predefined by Salesforce.

Custom notifications allow you to send important information to your users via push to mobile or desktop alerts. Now you can fully customize the notifications to inform users of record information, changes, and updates. Custom notifications will bring relevant information to your users at the right time!

 

 

Create Custom Notification Type

First of all, you need to create a Custom Notification Type in Setup.

This allows us to define the notification to be sent. When you create the notification you’ll want to make sure to check the supported channels for the notification.

For now, you can send a notification via Process Builder or via the REST API.

Send notification in Process Builder

When defining actions in Process Builder, you need to select: Send Custom Notification.

Once you select that option, you can fill in all the required information about the notification you want to send.

Send notification via the Rest API

If you want to send a notification via the Rest API, the first step is to get the Id of the notification you want to send. The easiest way to do this is to use the following query:

SELECT Id, CustomNotifTypeName FROM CustomNotificationType

Then you need to set up Rest API call with the Title and Body of the notification. Custom Notification payload can look like this:

curl --include --request POST \
--header "Authorization: Authorization: Bearer 00DR...xyz" \
--header "Content-Type: application/json" \
--data '{ "inputs" :
  [
  {
    "customNotifTypeId" : "0MLR0000000008eOAA",
    "recipientIds" : ["005R0000000LSqtIAG"],
    "title" : "Custom Notification",
    "body" : "This is a custom notification.",
    "targetId" : "001R0000003fSUDIA2"
  }
  ]
}' \
"https://instance.salesforce.com/services/data/v46.0/actions/standard/customNotificationAction"

More information about using API you can find in Custom Notification Actions Developer Documentation.

Send notification in Apex Code

Custom Notification does not have any Apex API, but you can invoke Rest API from Apex or run the Process Builder by an update in a certain field.

How notification looks like

When the criteria will be evaluated you will get the following notification in Desktop or Mobile App.

If you have any questions or problems related to Salesforce Development – let us know. We always glad to help you.