Send Custom Notifications Using Apex

Winter 21 release is bringing many great features for us. We are all excited. Here are some of my posts covering some of the important features that will come with the Winter 21 release -Winter 21 Admin New FeaturesWinter 21 Apex New FeaturesWinter 21 Flow EnhancementsIn today’s post, I will be discussing about the feature which will allow us to send custom notifications using Apex. Introduction of Custom NotificationCustom notifications are the customized notifications that can be sent when some action happened with Salesforce. For example, every time a new knowledge article is published, we can publish a custom notification to all the users/selected users. These notifications are real-time i.e. users don’t require to refresh their existing page to get the notification. On the same only, these notifications will be presented on the bell icon.Create Custom NotificationType ‘Notification’ in the setup searchClick ‘Custom Notifications’ under ‘Notification Builder’Click NewEnter the name for example – “Knowledge Notification”Select the channels (Mobile and/or Desktop).Apex Code to Send Notification//New Class introduced to deal with Custom NotificationsMessaging.CustomNotification singleNotification =                         new Messaging.CustomNotification();//Required – Setting up the BodysingleNotification.setBody(‘New Article is published’);//Required – Setting up the titlesingleNotification.setTitle(‘Check the new article!’);//Optional – Who is sending this notificationsingleNotification.setSenderId(Userinfo.getUserId());//Fetching the custom notification created and using that idCustomNotificationType type = [ SELECT Id                                 FROM CustomNotificationType               ...

Read More