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
Please enter at least three characters to search
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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • APIs Outside, Events Inside
  • APIs for Logistics Orchestration: Designing for Compliance, Exceptions, and Edge Cases
  • Build a REST API With Just 2 Classes in Java and Quarkus
  • Micronaut vs Spring Boot: A Detailed Comparison

Trending

  • Segmentation Violation and How Rust Helps Overcome It
  • Building Scalable and Resilient Data Pipelines With Apache Airflow
  • Java's Quiet Revolution: Thriving in the Serverless Kubernetes Era
  • Enhancing Avro With Semantic Metadata Using Logical Types
  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
DZone Core CORE ·
Feb. 12, 24 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
2.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
  • APIs for Logistics Orchestration: Designing for Compliance, Exceptions, and Edge Cases
  • Build a REST API With Just 2 Classes in Java and Quarkus
  • Micronaut vs Spring Boot: A Detailed Comparison

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and 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:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!