Skip to content

Instantly share code, notes, and snippets.

@ayub-ansari
Created April 25, 2019 17:42
Show Gist options
  • Save ayub-ansari/631454951cd8fe46c7bc14d2a9b8d7c9 to your computer and use it in GitHub Desktop.
Save ayub-ansari/631454951cd8fe46c7bc14d2a9b8d7c9 to your computer and use it in GitHub Desktop.
Custom Push Notification In Lightning Service Cosnole
public class CaseChangesPushNotification
{
public static void sendAgentMessage(String message)
{
Case_Event__e event = new Case_Event__e(Message__c=message);
Database.SaveResult result = EventBus.publish(event);
if (!result.isSuccess())
{
for (Database.Error error : result.getErrors())
{
System.debug('Error returned: ' +
error.getStatusCode() +' - '+
error.getMessage());
}
}
}
}
//CaseChangesPushNotification.sendAgentMessage('5000j000003CpsTAAS');
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<aura:attribute name="sub" type="map" />
<aura:attribute name="recordId" type="String" />
<lightning:empApi aura:id="empApi" />
<lightning:notificationsLibrary aura:id="notifLib"/>
</aura:component>
({
init : function(component, event, helper) {
var empApi = component.find("empApi");
var recordId = component.get("v.recordId");
console.log(recordId, '__ayub');
// Error handler function that prints the error to the console.
var errorHandler = function (message) {
console.log("Received error ", message);
}.bind(this);
// Register error listener and pass in the error handler function.
empApi.onError(errorHandler);
var channel='/event/Case_Event__e';
///data/AccountChangeEvent
var sub;
// new events
var replayId=-1;
var callback = function (message) {
//console.log(message, 'bam')
if(message.data.payload.Message__c == recordId){
component.find('notifLib').showNotice({
"title": "Case has been updated!",
"message": "Changed status to Pending with Agent. Please take a look.",
"variant":"info"
});
}
}.bind(this);
empApi.subscribe(channel, replayId, callback).then(function(value) {
console.log("Subscribed to channel " + channel);
sub = value;
component.set("v.sub", sub);
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment