1

My Requirement:- we want to display the notifications without reloading the page and without any streaming API. if any change happens on the record from a custom lightning page.

I have done some R&D. then I found something like PlatformEvents and empApi Components. I tried two scenario's Created One platform Event Object.

1) Publishing the notification from Process Builder and able to get notifications in Bell Icon.

2) Publishing the Notification from process builder. For Subscribing the event, created lightning component with help "empAPI component" and added my component to a lightning page, then I can able to see the notification in console. But if add the same component into Lightning Application, not able to see the notifications.

I guess event not subscribing, little confusing. Below is the code snippet.

Component:-

<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.init}" />
    <aura:attribute name="sub" type="map" />
    <lightning:empApi aura:id="empApi" />   
    <lightning:notificationsLibrary aura:id="notifLib"/>
</aura:component>

Controller:-

({
    init : function(component, event, helper) {
        alert('init() calling');        
        var empApi = component.find("empApi");
        var errorHandler = function (message) {
            console.log("Received error ", message);
        }.bind(this);
        empApi.onError(errorHandler);        
        var channel='/event/Custom_Notification__e';
        var sub;
        var replayId=-1;        
        var callback = function (message) {
            component.find('notifLib').showToast({
                "title": "Message Received!",
                "message": message.data.payload.Notification_Title__c
                });            
                console.log("Notification Title>>>>>>" + message.data.payload.Notification_Title__c);
        }.bind(this);
        empApi.subscribe(channel, replayId, callback).then(function(value) {
            console.log("Subscribed to channel " + channel);
            sub = value;
            component.set("v.sub", sub);
        });
    }
 })

Lightning App:-

<aura:application extends="force:slds">
     <aura:dependency resource="markup://force:*" type="EVENT"/>    
    <c:PESubscribe2/>    
</aura:application>

Could you please help any one.

Thanks

1

From the documenation of empApi , its only available in Lightning Experience. enter image description here

Your component needs to be inside Lightning experience.. not a standalone app, as the standalone app does not have enough libraries to support commetD.

  • Hi Pranay, Thanks for the reply – Ragavendra Oct 22 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.