5

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?

9
  • Are you using the same user (session) on machine #2? Jul 17, 2018 at 10:08
  • I have tried this with same and different users as well. @ChristianSzandorKnapp
    – d_k
    Jul 17, 2018 at 12:18
  • What if you update the Project__c records independently from the two Visualforce pages? The PushTopic should still notify any subscribers. Jul 21, 2018 at 10:05
  • Another verification to perform, use Workbench Queries > Streaming Push Topics to subscribe to the channel. That will tell you if it is your push topic or the Visualforce pages causing the problems. Jul 21, 2018 at 10:09
  • @DanielBallinger If I update the same Project__c from the individual pages it does notify the subscribers.
    – d_k
    Jul 22, 2018 at 9:19

1 Answer 1

1

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.

3
  • The sessionID's are different for both users, both the users have same profile.
    – d_k
    Jul 24, 2018 at 2:12
  • Is it always the same user who can't get the cometd updates? Jul 24, 2018 at 2:58
  • Not really, its inconsistent.
    – d_k
    Jul 24, 2018 at 4:16

You must log in to answer this question.

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