I want a functionality which automatically refreshes a lightning page when there is a update in the object record details. I'm trying with Streaming API to achieve this. But the page is not refreshed whenever there is a update in the record. Please let me know what else I need to add to make it work.
Here are the details.
PushTopic:
PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'QueueUpdates1';
pushTopic.Query = 'SELECT Id, Name, AgentsAvailable__c FROM Queue_Status__c';
pushTopic.ApiVersion = 36.0;
insert pushTopic;
Component:
<lightning:empApi aura:id="empApi"/>
<aura:handler name="init" value="{!this}" action="{!c.onInit}"/>
Controller:
onInit: function(component, event, helper) {
var action = component.get("c.getQueues");
action.setCallback(this, function(response){
if(response.getState()==="SUCCESS" && component.isValid()){
component.set("v.queues",response.getReturnValue());
}
});
$A.enqueueAction(action);
const empApi = component.find('empApi');
const channel = '/topic/QueueUpdates5';
empApi.setDebugFlag(true);
var handleError = function (error) {
console.log('empApi error', error);
};
empApi.onError(handleError);
empApi.subscribe(channel, -1, $A.getCallback(eventReceived => {
console.log('Received event ', JSON.stringify(eventReceived));
component.set("v.queueDetail",eventReceived.data.sobject);
}));
}