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() {
j$.cometd.init({
url: URL,
requestHeaders: {Authorization: 'OAuth ' + SESSION_ID}
});
j$.cometd.subscribe('/topic/AggregateUpdate', function(message) {
console.log('========== Response :: ' + JSON.stringify(message.data));
j$('#' + message.data.sobject.Id).find('a').addClass('disableCursor');
j$('#' + message.data.sobject.Id).find('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?
Project__c
records independently from the two Visualforce pages? The PushTopic should still notify any subscribers.