5

Here's a side-by-side showing the issue that I'm currently facing. On the left, we have streaming api version 36.0, and on the right we have streaming api version 37.0 (all higher api versions had the same effect). Besides the api version, everything else between these two pages was the same.

enter image description here

I have a Visualforce page:

  1 <apex:page 
  2  showHeader="false"
  3  showChat="false"
  4  sidebar="false" 
  5  standardStylesheets="false">
  6 
  7 <span id="sid" data-sid="{!$Api.SESSION_ID}" />
  8 
  9 <script type="text/javascript" src="{!URLFOR($Resource.cometd_3_1_3,'cometd.js')}" />
 10 <script type="text/javascript" src="{!URLFOR($Resource.cometd_3_1_3,'AckExtension.js')}" />
 11 <script type="text/javascript" src="{!URLFOR($Resource.cometd_3_1_3,'ReloadExtension.js')}" />
 12 <script type="text/javascript" src="{!$Resource.stream}" />
 13 
 14 
 15 </apex:page>

A javascript file to run cometd, where the variable version in line 2 is the only thing I changed between the two pages.

  1 
  2 var version = '37.0'  
  3   , sid = document.getElementById('sid').dataset.sid
  4   , sfConfig = {
  5         url : 'https://' + window.location.hostname + '/cometd/' + version
  6     ,   requestHeaders : { Authorization: 'Bearer ' + sid }
  7     }
  8   , callback = function(){ console.log(arguments) }
  9 
 10 cometD = new org.cometd.CometD() ;
 11 cometD.websocketEnabled = false;
 12 
 13 cometD.configure( sfConfig );
 14 cometD.handshake();
 15 cometD.subscribe('/topic/myobj',callback);
 16 

A push topic:

PushTopic:
{ Id=0IF0I000000fyMiWAI
, Name=myobj
, Query=SELECT Id FROM Analysis__myobj__c
, ApiVersion=30.0
, NotifyForOperations=All
, NotifyForFields=All
, NotifyForOperationCreate=true
, NotifyForOperationUpdate=true
, NotifyForOperationDelete=true
, NotifyForOperationUndelete=true }

And I manually updated a record in the UI only once with both pages open subscribing to the push topic.

Has anyone else seen this behavior from the streaming api before, and is there a work-around besides lowering the version number?

5

It seems that with the newer streaming api versions, the initial update of a record generates an event, and then when field update actions from the workflow rules fire, another event is generated. So even though these two update events are happening milliseconds apart in the same execution context, there are two updates happening, and they both get sent over the streaming api.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.