I have created a demo of streaming api. I have followed all the steps which have mentioned in the dec for streaming api as same http://www.salesforce.com/developer/docs/api_streaming/. The only thing is that I named my PushTopic as AccountUpdates and used my account object instead of invoice custom object all also updated the name of PushTopic in my Vf page also and activated the PushTopic from user interface.

My code

PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'AccountUpdates';
pushTopic.Query = 'SELECT Id, Name FROM Account';
pushTopic.ApiVersion = 31.0;
pushTopic.NotifyForOperationCreate = true;
pushTopic.NotifyForOperationUpdate = true;
pushTopic.NotifyForOperationUndelete = true;
pushTopic.NotifyForOperationDelete = true;
pushTopic.NotifyForFields = 'Referenced';
insert pushTopic;

My Visualforce page

<apex:page sidebar="false">
    <apex:includeScript value="{!$Resource.cometd}"/>
    <apex:includeScript value="{!$Resource.jquery}"/>
    <apex:includeScript value="{!$Resource.json2}"/>
    <apex:includeScript value="{!$Resource.jquery_cometd}"/>
    <script type="text/javascript">
            $(document).ready(function() {
                    // Connect to the CometD endpoint
                         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/AccountUpdates', 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) + 

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

But I am not able to see any updates in my Visualforce page if I update it or create records. But when I try to use workbench it works and display update over there. Please do help me out getting confused.


2 Answers 2


A few suggestions:

Make sure there's a div on your page with id="content"

Throw a js console.log(message) before the append functions, in case the API is working fine but your js isn't.

Finally, I always use $j=jQuery.noConflict(); and then $j instead of $ when using jQuery on visualforce.

  • Thanks for your suggestion. I not to gud with jQuery can you please let me know which line of code I need to replace with $j=jQuery.noConflict();
    – Anu
    Commented Sep 7, 2014 at 3:25
  • 1
    Anu, insert the line right at the start of your javascript, before (function($){ and then use j$ in place of $ throughout the rest of your code. Salesforce already has a version of jQuery bound to $ and that can intefere with your own code.
    – Matt Lacey
    Commented Sep 10, 2014 at 0:57

I had the same issue the first time I went through the Streaming API tutorial.

** Double and triple check that you loaded your static resources right... specifically checking that the right FILE has been labeled with the right SFDC resource NAME that your code is calling **


The Files


File/ Static Resource Name

cometd.js/ cometd
jquery-1.5.1.js/ jquery
json2.js/ json2
jquery.cometd.js/ jquery_cometd

*** Don't just upload the .war as your "cometd", you have to go in there and pull out the right .js file.

You must log in to answer this question.

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