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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • APIs Outside, Events Inside
  • Spring Boot 3.2: Replace Your RestTemplate With RestClient
  • Building and Integrating REST APIs With AWS RDS Databases: A Node.js Example
  • Building a REST Application With Oracle NoSQL Using Helidon

Trending

  • Vector Tutorial: Conducting Similarity Search in Enterprise Data
  • How To Get Started With New Pattern Matching in Java 21
  • How to Submit a Post to DZone
  • Service Mesh Unleashed: A Riveting Dive Into the Istio Framework
  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 user avatar
Jaseem Pookandy
·
Feb. 12, 24 · Tutorial
Like (1)
Save
Tweet
Share
1.4K Views

Join the DZone community and get the full member experience.

Join For Free

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
  • Spring Boot 3.2: Replace Your RestTemplate With RestClient
  • Building and Integrating REST APIs With AWS RDS Databases: A Node.js Example
  • Building a REST Application With Oracle NoSQL Using Helidon

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: