11

Original Question: What's the lastest version of CometD that can be used with Streaming API?


In Salesforce Streaming API documentation, it says Salesforce uses CometD version 2.0. But in their code example, Salesforce says to download CometD version 2.2. What's the latest version of CometD that can be used with Streaming API?

I tried the lastest version of CometD, 3.0.4, but I couldn't get Streaming API working.

CometD version 2.2 uses jQuery version 1.5.1, but I'd really like to use jQuery 1.11+ so I can use it with other libraries like Bootstrap.


Edited Question: How can I use jQuery 1.11+ while also using Streaming API?

CometD version 2.2 uses jQuery version 1.5.1, but I'd really like to use jQuery 1.11+ so I can use it with other libraries like Bootstrap.

2 Answers 2

4
+200

I ran a search using http://findsf.info/ and could only find references to Salesforce supporting ver 2.20 of CometD. By chance, I came across something else that may be of use to you. It's a reference to using NodeJS with the Streaming API that was linked to a Blog on how to use CometD and the Streaming API with Order Information Objects to create push topics. The linked article was written by Jeff Douglass. It might assist in satisfying your requirements to use something other than jQuery 1.51.

The original post that included using CometD and jQuery 1.51 was written by Bryan Leboff and titled The Salesforce Streaming API (with example!). Linked to it was Catching Salesforce Outbound Messages with NodeJS by Jeff Douglass which is an app to push messages to phones from workflow.

2
  • I updated the Question to be more specific to what I'm really looking for. You answered the Original Question satisfactorily, so I awarded you the bounty. Thanks. Commented Jun 18, 2015 at 21:49
  • I saw the points awarded. Thank you. I also saw your answer posted on the workaround for JQuery versioning. Glad you found a satisfactory solution.
    – crmprogdev
    Commented Jun 18, 2015 at 21:57
1

Original Question: This doesn't answer the original question of what's the latest version of CometD that can be used with Streaming API (@crmprogdev answer of CometD version 2.2.0 is by all accounts correct).

Edited Question: But the following is a work-around to use any version of jQuery while still using jQuery 1.5.1 for Streaming API:

Instead of using Streaming API on the Visualforce Page in question, use it on another Page which is then embedded in an iframe on the Page in question.

On the Parent Page, use any version of jQuery, and create a JS function to handle the Streaming API response. For example, call the function handleStreamingApiResponse(meassage).

Then on the Iframed Page, use the version of jQuery required for Streaming API and do all of the Streaming API JavaScript here. To handle the Streaming API response call the Parent's Streaming API Handler. In the example, this would be window.parent.handleStreamingApiResponse(message).

Note: The Example below follows the Streaming API Visualforce Code Example.

Parent Page

<apex:page ... >
    <apex:includeScript value="{!URLFOR($Resource.jQuery_1_11_1}"/>
    <script>
        var $ = jQuery.noConflict();

        function handleStreamingApiResponse(message){
           ...
        }
    </script>
    <apex:iframe src="/apex/iframedPage" height="0"/>
    ...
</apex>

Iframed Page

<apex:page ...>
    <apex:includeScript value="{!$Resource.cometd}"/>
    <apex:includeScript value="{!$Resource.jquery_1_5_1}"/>
    <apex:includeScript value="{!$Resource.json2}"/>
    <apex:includeScript value="{!$Resource.jquery_cometd}"/>
    <script>
        var $ = jQuery.noConflict();

        (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/MyTopic', function(message) {
                    window.parent.handleStreamingApiResponse(message); 
                });
            });
        })(jQuery)
        function disconnect() {
            $.cometd.disconnect();
        }
        window.onbeforeunload = disconnect;
    </script>
</apex:page>

Note: When viewing the Parent Page with Development Mode turned on, the function window.parent.handleStreamingApiResponse(message) won't work because the Development Mode Panel changes the order of iframes. It turns out that with Development Mode on, Parent Page isn't the direct parent of Iframed Page nor is Parent Page the top-most window (in case you wanted to try window.top.handleStreamingApiResponse(message)).

If you turn off Development Mode, you will see handleStreamingApiResponse() work.

You must log in to answer this question.

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