Skip to main content
formatting
Source Link
Oleh Berehovskyi
  • 7.8k
  • 7
  • 30
  • 54

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

I have done some R&D. then iI 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 cosnole. But if add the same component into Lightning Application, not able to see the notifications.

  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.

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

<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>

<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>

({ 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); }); } })

({
    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);
        });
    }
 })

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

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

My Requirement:- we want display the notifications without reloading the page and with out any streaming api. if any change happen on the record from 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 cosnole. 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.

<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>

({ 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); }); } })

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

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.

<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>
({
    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);
        });
    }
 })
<aura:application extends="force:slds">
     <aura:dependency resource="markup://force:*" type="EVENT"/>    
    <c:PESubscribe2/>    
</aura:application>
Source Link

Unable to subscribe platform events using "lightning:empApi" in lightning component via ligthning application

My Requirement:- we want display the notifications without reloading the page and with out any streaming api. if any change happen on the record from 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 cosnole. 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