Shoot Your Custom Notifications Via Apex

       Summer 19 bought a lot of surprises and one of the most enchanting one was that to send custom bell notifications from our inmate, the "Process Builder".

      Custom notifications are the soul of the modern business. This feature allows you to send important information, via push to mobile or desktop alerts.

   Notifications can be tailor made to inform users regarding any of the record update. Custom Bell Notifications provide the flexibility of showcasing relevant information at the right time to our users.

       All these involves just a handful of steps.

      From setup, enter Custom Notifications in the quick find box.

     Create a new custom notifications type, also define either desktop or phone to pop-up your notifications. You can select both the locations.

       Hope that was simple, now the fun part begins.

      Guess what you can create your own custom object. In my example I have created the object with the name Custom Push Notification.

       Now let’s get our hands dirty. Until now I was scratching the surface.





       Once you created the Notification type, now ready to create custom object "Custom Push Notification".



        Create below fields in Custom Push Notification object. 



       Here's the snippet for inserting the record into object  “Custom_Push_Notification__c”.


  Few points to notice.

       In my example I have taken Opportunity object, you guys can take any custom or standard object.

      I have kept my title and message in custom labels. This gives the flexibility of configuration. 
With these few lines of code you have completed the penultimate step for sending the custom notifications.

public class UtilityHelper {

public static void sendBellNotification() {
        Custom_Push_Notification__c notificationRecord = new Custom_Push_Notification__c();
        notificationRecord.OwnerId = OwnerId;
        notificationRecord.Opportunity__c = OpportunityId;
        notificationRecord.On_Screen_Notification_Title__c = System.Label.TitleTemplate;
        notificationRecord.On_Screen_Notification_Message__c = System.Label.MessageTemplate;
        insert notificationRecord;

    }
}

One last nail in the coffin

        It's time to create a Process builder on the Custom_Push_Notification__c  object.
On insert of the object record select and define the following action, shared in the screen shot.


       Hurray you have successfully learned to send custom notification from apex controller which are the primary aspect of any business with straightforward.

Comments

Popular posts from this blog

Communicating between Independent LWC in Omniscript

Salesforce Best Features available

Efficient way to write apex code