How to send notifications to bell icon in Salesforce

Salesforce allows us to send custom notifications to bell icon in lightning experience using "custom notification" feature. These custom notifications can be sent using process builders or flows or REST API.

Unfortunately there is no native method in apex that you can just call to send notification yet. One work around is to make a a callout to Salesforce rest endpoint from Apex. In this blog we will go through examples of sending custom notifications through different channels.

Use cases

  • Can be used to send notifications to desktop/lightning experience bell icon or to Salesforce mobile app as push notification
  • Any scenario of when you need to get user's attention in Salesforce. For example, notify sales agent about an activity on an opportunity they are working on, notify administrator about failures in a critical API call etc

Using apex to send notification



Explanation

Salesforce still hasn't made the ability to send custom notifications from apex available in apex. So we need to call Salesforce REST API (Custom Notification Actions) from apex to to trigger the notifications.

In this example we are expecting a custom notification to be created from setup with name Error Notification. Once you have a the custom notification setup, you can just call the method using below syntax.



Steps to send notification through configuration

  1. Create a custom notification from setup


  2. Create a process builder entry to fire on updates of opportunity records


  3. Example. Update any opportunity and see result in bell icon


No comments:

Post a Comment