DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • APIs Outside, Events Inside
  • How to Secure Fintech REST APIs Against BOLA Vulnerabilities
  • HTTP QUERY in Java: The Missing Method for Complex REST API Searches
  • Evolving Spring Boot APIs to an Event-Driven Mesh

Trending

  • Spring AI on Local LLMs
  • Build a Voice Assistant With Gemini Live API
  • AI Agents Need an Identity Plane: Rethinking Enterprise Authorization for Autonomous Software
  • The Self-Hosting Math Changed While We Were Still Arguing About Sovereignty

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Send Alerts to Salesforce Users Through Custom Bell Notifications

Send Alerts to Salesforce Users Through Custom Bell Notifications

You can create alerts or notifications for desktop and mobile users in Salesforce using the custom notification feature.

By 
Jaseem Pookandy
DZone Core CORE ·
Feb. 12, 24 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
3.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Your sales agents or service reps are busy managing their workflows in Salesforce. Timely attention to key events is necessary for these users to be effective in their roles. Alerts or notifications play a crucial role in providing real time information for Salesforce users and their managers on key changes that need immediate attention. For example, you can alert sales agents regarding key changes in their opportunities or service agents on cases that need immediate attention. This article talks about different ways you can set up notifications in Salesforce. 

Salesforce's bell notifications for users are available for both desktop and mobile apps. You can customize the title and body for these notifications so that it suits your business use case. You can also define a target navigation page so that when a notification is clicked, the user lands on that page. You have two options for navigation target — to a record page or a page reference in Salesforce. You must specify one target for your notification.

You can create notifications in three different ways.

  1. REST API
  2. Apex
  3. Flow

The first step for bell notification is to set up a 'custom notification' metadata. 

custom notifications

edit custom notification type

Required Attributes for Custom Notification

  1. Title: Title of the notification. 
  2. Body: Message body of the notification. 
  3. Notification Type ID: Required. ID of the notification type we created above. You can get it by following SOQL. 
 
Select id,CustomNotifTypeName, DeveloperName from CustomNotificationType where DeveloperName = 'Email_Alert'


4. Recipient ID: ID of the recipient (user) or recipient type (account ID, opportunity ID, group ID, queue ID). 

5. Target: This could be a record ID or a page reference. Either one should be specified. 

your opportunity is changed

Create Notifications via REST API

You can create notifications using REST API. This is useful when you need to alert your sales agents regarding any events that are external to Salesforce. An external system can ping Salesforce using this REST API to alert agents. Following are the API details. 

  • HTTP Method: POST
  • URI:/services/data/vXX.X/actions/standard/customNotificationAction 
  • Payload: If the target is recorded Id. 
JSON
 
{
   "inputs":[
      {
         "customNotifTypeId":"0MLR0000000008eOAA",
         "recipientIds":[
            "005R0000000LSqtIAG"
         ],
         "title":"Your opportunity is changed",
         "body":"Please jump to your pipeline management",
         "targetId":"001R0000003fSUDIA2"
      }
   ]
}


If the target is page reference:

JSON
 
{
   "inputs":[
      {
         "customNotifTypeId":"0MLR0000000008eOAA",
         "recipientIds":[
            "005R0000000LSqtIAG"
         ],
         "title":"Your opportunity is changed",
         "body":"Please jump to your pipeline management",
         "targetPageRef": {
    			type: 'standard__navItemPage',
    			attributes: { apiName: 'MyCustomTabName'}
			}
      }
   ]
}


Create Notification via Apex

You can create notifications using Apex. This is useful when your events are within Salesforce and if you want to trigger creating notifications using an apex trigger or batch jobs. Following are the details. 

  1. Create an instance of Messaging.CustomNotification using the default constructor. 
  2. Use different setter methods to set the required attributes for the custom notification. 
Java
 
Messaging.CustomNotification customNotificationObj = new Messaging.CustomNotification();
Id userId = Userinfo.getUserId();
customNotificationObj.setBody('Please jump to your pipeline management');
customNotificationObj.setTitle('Your opportunity is changed!!');
CustomNotificationType type = [select id,CustomNotifTypeName, DeveloperName, Description from CustomNotificationType where DeveloperName = 'Email_Alert'];
customNotificationObj.setNotificationTypeId(type.id);
customNotificationObj.setSenderId(userId);
String addressTest =
'' +
'    {' +
'        type: \'standard__navItemPage\', ' +
'        attributes: {' +
'            apiName: \'Pipeline_Management\'' +
'        }'+
'   }'+
'';
customNotificationObj.setTargetPageRef(addressTest);
customNotificationObj.send(new Set<String> {userId});


The important thing to note here is that the send method can be used only for one notification at a time. It cannot be used to send multiple notifications at a time. 

Create Notifications via Flow

You can also create notifications without a single line of code using flows. 

Create Notification via Apex

Conclusion

Salesforce bell notifications can be used to alert your users on key events that need timely attention. There are three different ways you can create notifications in Salesforce — API, Apex, or Flow. You can customize these notifications with a title and body that suits your business use case. You should also define target navigation for these notifications so that users land on an appropriate page for further actions.

API REST Event Flow-based programming

Opinions expressed by DZone contributors are their own.

Related

  • APIs Outside, Events Inside
  • How to Secure Fintech REST APIs Against BOLA Vulnerabilities
  • HTTP QUERY in Java: The Missing Method for Complex REST API Searches
  • Evolving Spring Boot APIs to an Event-Driven Mesh

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook