How to create Custom notification?
Go to Setup and Click on Custom Notification in Notification Builder.
Click the New button to create a new custom Notification.
Enter Custom Notification Name, API Name and Supported Channels as follows,

Click the Save button.
Custom Notification for Internal Users using APEX:
The below example shows how to send a custom notification when the related contact is delinked. Call this method from a trigger, flow, or wherever you want to send a custom notification from an Apex Class.
Code Snippet:
public class CARS_CustomNotification {
//This method is used to send notification when the related contact is delinked.
Public static void sendNotification(AccountContactRelation currAccCon){
       //Get the custom Notification type
List<CustomNotificationType > TemplateInfoDetail = [SELECT Id, DeveloperName FROM CustomNotificationType
                                                                                                                                                                                  WHERE DeveloperName=’Notify_Delink’];
if(currAccCon.CARS_IsActive__c == false && currAccCon.CARS_ContactUser__c != Null){
// Create a new custom notification
Messaging.CustomNotification currNotification = new Messaging.CustomNotification();
// Set the contents for the delinking notification
currNotification.setTitle(‘You have been DeLinked’ + currAccCon.CARS_Account_Name__c);
currNotification.setBody(currAccCon.CARS_Contact_Name__c + ‘ has de-linked from ‘ + currAccCon.CARS_Account_Name__c +
‘ on ‘ + system.today());
// Set the notification type and target
currNotification.setNotificationTypeId(TemplateInfoDetail[0].Id);
currNotification.setTargetId(currAccCon.CARS_ContactUser__c);
// Send the notification
try {
currNotification.send(currAccCon.CARS_ContactUser__c);
}
catch (Exception ex) {
System.debug(‘Notification Failed: ‘ + ex.getMessage());
}
}
}
}
Considerations:
- Custom Notifications are used to send notification for internal users.
Workaround
To notify the External users, an Email Alert can be used in the immediate action of the Process Builder in place of the Notification to notify the desired recipient.
- Bulk Notifications are not supported using APEX, since it is designed to notify a bunch of people with single update, not for bulk updates.
Workaround
For Bulk Notification, use Process Builder or restructure your logic using Batch or Queueable class.
- It is available only in Lightning Experience.