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.
Publishing the notification from Process Builder and able to get notifications in Bell Icon.
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>