Streaming API response on multiple windows

I have a VF page let’s call it Aggregator.

I display Project__c records on this page in a table, each row has a ‘Refresh’ icon on click of which a batch runs.

The batch then does some calculation on all the child records of that Project__c record and then updates a Value__c field on Project__c record in the finish() method of the batch.

I created a PushTopic:

PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'AggregateUpdate';
pushTopic.Query = 'SELECT Id, Value__c FROM Project__c WHERE Type__c = \'Aggregated\'';
pushTopic.ApiVersion = 43.0;
pushTopic.NotifyForOperationUpdate = true;
pushTopic.NotifyForFields = 'Referenced';
insert pushTopic;

In my VF page, I have subscribed to the PushTopic:

function loadCometD() {
        url: URL,
        requestHeaders: {Authorization: 'OAuth ' + SESSION_ID}

    j$.cometd.subscribe('/topic/AggregateUpdate', function(message) {
        console.log('========== Response :: ' + JSON.stringify(;
        j$('#' +'a').addClass('disableCursor');
        j$('#' +'a').find('.slds-icon').attr('class', 'disableIcon');

loadCometD() is called onLoad() of the VF page

Once the field is updated the icon is greyed out and is disabled. This is how it should work.

Now, If I open this same page on two different machines and run the batch from machine #1 the batch runs fine and updates the value__c field.
This is the response I get on machine #1:

========== Response :: {"event":{"createdDate":"2018-07-13T10:19:07.346Z","replayId":941,"type":"updated"},"sobject":{"Value__c":"2034450","Id":"a0L6F00001EG8CkUAL"}}

========== Response :: {"event":{"createdDate":"2018-07-13T10:19:22.546Z","replayId":942,"type":"updated"},"sobject":{"Value__c":"2034450","Id":"a0L6F00001EG8CkUAL"}}

Shouldn’t the second response be displayed on machine #2? The icon on #1 is greyed out and is disabled while nothing has changed on #2.

I want to change the icon on all the machines accessing this Aggregator page.
How can I achieve this?


Based of the conversation in the comments I’d say there is something wrong with the cometD setup in the Visualforce pages.

That causing the PushTopic to fire outside of the Visualforce page doesn’t show an update on either Visualforce page suggests that neither is receiving the updates as expected.

You could further verify this using something like Workbench to subscribe to the PushTopic channel. See Workbench Queries > Streaming Push

The SessionID that the Visualforce pages are using seems like one possible culprit. Check what value {!$Api.Session_ID} is returning for the Session Id in the Visualforce pages. I assume you are using the same user on both machines. If not, it might be an issue with user permissions.

Source : Link , Question Author : d_k , Answer Author : Daniel Ballinger

Leave a Comment