+ Start a Discussion
gbu.varungbu.varun 

Streaming API not running

Hi,

 

I have developed a VF for Streaming API which is working fine in developer edition. When I am running same code in another developer edition it is not running. I think there is some setting missing. Please help me.

 

<apex:page >
    <apex:includeScript value="{!$Resource.cometd}"/>
    <apex:includeScript value="{!$Resource.jquery1}"/>
    <apex:includeScript value="{!$Resource.json2}"/>
    <apex:includeScript value="{!$Resource.jquery_cometd}"/>
    <script type="text/javascript">
        (function($){
            $(document).ready(function() {
                // Connect to the CometD endpoint
                $.cometd.init({
                url: window.location.protocol+'//'+window.location.hostname+'/cometd/24.0/',
                requestHeaders: { Authorization: 'OAuth {!$Api.Session_ID}'}
                });
                // Subscribe to a topic. JSON-encoded update will be returned
                // in the callback
                $.cometd.subscribe('/topic/Push', function(message) {
                $('#content').append('<p>Notification: ' +
                'Channel: ' + JSON.stringify(message.channel) + '<br>' +
                'Record name: ' + JSON.stringify(message.data.sobject.Name) +
                '<br>' + 'ID: ' + JSON.stringify(message.data.sobject.Id) +
                '<br>' + 'Event type: ' + JSON.stringify(message.data.event.type)+
                '<br>' + 'Created: ' + JSON.stringify(message.data.event.createdDate)
                +
                '</p>');
                });

            });
        })(jQuery)
    </script>
    
    <body>
        <div id="content">
            <h1>Streaming API Test Page</h1>
            <p>This is a demonstration page for Streaming API. Notifications from the
            InvoiceStatementUpdates channel will appear here...</p>
        </div>
    </body>
</apex:page>

 

 

 

Boman@imtBoman@imt

Did you create hte PushTopics in the second org too?

gbu.varungbu.varun

Yes I created. 

gbu.varungbu.varun

Here is my code to create push topic.

 

PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'Push';
pushTopic.Query = 'Select id, name from Account';
pushTopic.ApiVersion = 29.0;
pushTopic.NotifyForOperationCreate = true;
pushTopic.NotifyForOperationUpdate = true;
pushTopic.NotifyForOperationUndelete = true;
pushTopic.NotifyForOperationDelete = true;
pushTopic.NotifyForFields = 'Referenced';
insert pushTopic;

 

Boman@imtBoman@imt
Once created, can you bring up SOQLExplorer and see this PT "object"
executing?
gbu.varungbu.varun

Hi Boman,

 

I am able to see notification in workbench but not in Salesforce.  I am not able to run following command

$.cometd.init({
                url: window.location.protocol+'//'+window.location.hostname+'/cometd/24.0/',
                requestHeaders: { Authorization: 'OAuth {!$Api.Session_ID}'}
                });

I think I am hitting any ouath or api limitation.