0

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;
2

1 Answer 1

-2

Use Jquery 1.5.1 as in the example, jquery-2.1.3.js may be the issue.

1
  • Eh, it is an answer to some degree. It's the same recommendation I made in the comments, but the OP never responded if they'd tried it.
    – Adrian Larson
    Commented Jul 27, 2018 at 3:21

You must log in to answer this question.

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