I am trying to replicate one example given below in streaming api. I have used all the required component, still the page is not refreshing automatically.
I am using example from below link -
http://forceguru.blogspot.in/2012/12/streaming-apis-easy-code.html
Below are the code i have used -
Vf Page -
<apex:page id="PG" controller="StreamingAPIController">
<apex:form id="FRM">
<apex:includeScript value="{!URLFOR($Resource.streamapi, 'Cometd.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.streamapi, 'jquery-2.1.3.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.streamapi, 'json2.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.streamapi, 'jquery.cometd.js')}"/>
<apex:actionFunction name="GetRefreshedAccounts" reRender="PB,PBT"/>
<script type="text/javascript">
(function($)
{
$(document).ready(function() {
// Connect to the CometD endpoint
$.cometd.init({
url: window.location.protocol+'//'+window.location.hostname+'/cometd/34.0/',
requestHeaders: { Authorization: 'OAuth {!$Api.Session_ID}'}
});
// Subscribe to a topic. JSON-encoded update will be returned in the callback
// In this example we are using this only to track the generated event
$.cometd.subscribe('/topic/RefreshAccounts', function(message)
{
//You can use message as it will return you many attributes
//I am just using to track that event is generated
GetRefreshedAccounts();
});
});
})(jQuery)
</script>
<apex:pageBlock id="PB">
<apex:variable var="count" value="{!0}" />
<apex:pageBlockTable id="PBT" value="{!getRefreshedAccount}" var="AllAcc">
<apex:column headerValue="S.No.">
<apex:variable var="count" value="{!count+1}" />
{!count}
</apex:column>
<apex:column value="{!AllAcc.Name}" headerValue="Name"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class -
public class StreamingAPIController
{
//Everytime page is reRendered it will get refreshed values of account
public List<Account> getRefreshedAccount
{
get
{
return [select Id, Name from Account LIMIT 50000] ;
}
set;
}
public StreamingAPIController()
{
}
}
PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'RefreshAccounts';
pushTopic.Query = 'SELECT Id, Name FROM Account';
pushTopic.ApiVersion = 34.0;
pushTopic.NotifyForFields = 'Referenced';
insert pushTopic;