2

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

    }      

1 Answer 1

0

The problem here was : I was using my component in a standalone app , but empApi won't work with a standalone app . I added it to lightning experience (sales cloud) as per answers/comments mentioned in Lightning Component empAPI in LightningApp and it is working fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .