Skip to content

Instantly share code, notes, and snippets.

@arun12209
Created August 7, 2022 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun12209/67d636acaf72c694413ff2815b845c33 to your computer and use it in GitHub Desktop.
Save arun12209/67d636acaf72c694413ff2815b845c33 to your computer and use it in GitHub Desktop.
({
doInit : function(component, event, helper) {
//get the platform event channel
var channel = '/event/Activity_Event__e';
const replayId = -1;
//get the empAPI component
const empApi = component.find("empApi");
//A callback function that's invoked for every event received
const callback = function (message) {
var result = message.data.payload;
console.log('msg = '+JSON.stringify(result));
console.log('Activity_Record_ID__c : ' +result.Activity_Record_ID__c );
console.log('What_ID__c : ' +result.What_ID__c );
console.log('Who_ID__c : ' +result.Who_ID__c );
if(result.What_ID__c == component.get("v.recordId") || result.Who_ID__c == cmp.get("v.recordId"))
{
helper.navigateToActivityRecord(component,event,helper,result.Activity_Record_ID__c);
}
};
// Subscribe to the channel and save the returned subscription object.
empApi.subscribe(channel, replayId, callback).then(function(newSubscription) {
//console.log("Subscribed to channel" + channel);
});
const errorHandler = function (message) {
console.error("Received error ", JSON.stringify(message));
};
//A callback function that's called when an error response is received from the server for the handshake, connect, subscribe, and unsubscribe meta channels.
empApi.onError(errorHandler);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment