function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
davidbtdavidbt 

Error trying to do the Visualforce sample of Streaming Api

I've tried to do the sample 'Receiving Notifications in a Visualforce Page' of the page http://wiki.developerforce.com/index.php/Getting_Started_with_the_Force.com_Streaming_API

 

I'm doing everything as it comes in the document but don't get it to work. I'm on the na12 instance. When I try it on Chrome It gives me these errors

 

POST https://c.na12.visual.force.com/cometd/handshake 401 (Request requires authentication)

 

I also tried the equivalent sample of the document http://www.salesforce.com/us/developer/docs/api_streaming/api_streaming.pdf (page 11) but It gives me these errors

 

Uncaught TypeError: Object [object Object] has no method 'reset'
org.cometd.LongPollingTransport.resetcometd_js:2102
resetcometd_js:120
_handshakecometd_js:730
handshakecometd_js:1421
initcometd_js:1409
(anonymous function)StreamingPagePDF:89
d.extend._Deferred.f.resolveWithjquery.min.js:16
d.extend.readyjquery.min.js:16
c.addEventListener.y

 

I don't know what to do

 

Thank you in advance

 

David

VM_SFDCVM_SFDC

http://wiki.developerforce.com/index.php/Getting_Started_with_the_Force.com_Streaming_API is obsolete. Apologies for the confusion. We'll have it updated soon.

 

Here is the latest doc:

 

http://www.salesforce.com/us/developer/docs/api_streaming/index.htm

http://www.salesforce.com/us/developer/docs/api_streaming/api_streaming.pdf

 

The release notes are here: https://eu1.salesforce.com/help/doc/en/salesforce_winter12_release_notes.pdf


(page#103)

 

There are 3 important changes that you need to be aware of:

 

1. The sessionid / oauth token now needs to go with the Authorization header, instead of cookies (example: Authorization: OAuth <sessionId>)

2. API version is now required in the URL: example: https://instance.salesforce.com/cometd/23.0

3. topic names are now prefixed with "/topic" (example: /topic/AllAccounts)

 

 



Pat PattersonPat Patterson

For the record - I just updated the Getting Started with the Force.com Streaming API article to reflect the changes in the Winter '12 release.

 

Cheers,

 

Pat

Chirag MehtaChirag Mehta

Even after following the updated wiki article, the VF page shows nothing and the console says "Uncaught error"

 

Chrome JS console says

 

Fri, 11 Nov 2011 07:28:15 GMT 1 : ID=20339 *SCRIPT* rf_CS_onLoad. Script loaded! url=https://c2c.na12.visual.force.com/apex/StreamingPageWiki
Fri, 11 Nov 2011 07:28:15 GMT 6 : ID=20339 *SCRIPT* rf_sendMessageToBG. CS -> BGO : cmd:clearCS g_docnum:54394416
Fri, 11 Nov 2011 07:28:15 GMT 58 : ID=20339 *SCRIPT* rf_CS_receiveBG. COMMAND=setdocnum
Fri, 11 Nov 2011 07:28:15 GMT 58 : ID=20339 *SCRIPT* rf_CS_receiveBG g_docnum=0 Also eval language localization data
  1. C2C__cometd:23Uncaught ReferenceError: org is not defined
  1. C2C__jquery:869Uncaught TypeError: Cannot call method 'init' of undefined
Fri, 11 Nov 2011 07:28:16 GMT 1 : ID=3217 *SCRIPT* rf_CS_onLoad. Script loaded! url=https://c2c.na12.visual.force.com/apex/StreamingPageWiki?core.apexpages.devmode.url=1
Fri, 11 Nov 2011 07:28:16 GMT 5 : ID=3217 *SCRIPT* rf_sendMessageToBG. CS -> BGO : cmd:clearCS g_docnum:42805245
Fri, 11 Nov 2011 07:28:16 GMT 37 : ID=3217 *SCRIPT* rf_CS_receiveBG. COMMAND=setdocnum
Fri, 11 Nov 2011 07:28:16 GMT 37 : ID=3217 *SCRIPT* rf_CS_receiveBG g_docnum=1 Also eval language localization data
 
Chirag MehtaChirag Mehta

If I follow the pdf solution (http://www.salesforce.com/us/developer/docs/api_streaming/api_streaming.pdf), VF page shows no notification and the JS console shows an error "Uncaught TypeError: Object [object Object] has no method 'reset'"

 

Fri, 11 Nov 2011 07:41:43 GMT 1 : ID=33865 *SCRIPT* rf_CS_onLoad. Script loaded! url=https://c2c.na12.visual.force.com/apex/StreamingPage
Fri, 11 Nov 2011 07:41:43 GMT 7 : ID=33865 *SCRIPT* rf_sendMessageToBG. CS -> BGO : cmd:clearCS g_docnum:29740508
Fri, 11 Nov 2011 07:41:43 GMT 271 : ID=33865 *SCRIPT* rf_CS_receiveBG. COMMAND=setdocnum
Fri, 11 Nov 2011 07:41:43 GMT 271 : ID=33865 *SCRIPT* rf_CS_receiveBG g_docnum=0 Also eval language localization data
  1. C2C__cometd_js:2102Uncaught TypeError: Object [object Object] has no method 'reset'
Fri, 11 Nov 2011 07:41:43 GMT 1 : ID=83030 *SCRIPT* rf_CS_onLoad. Script loaded! url=https://c2c.na12.visual.force.com/apex/StreamingPage?core.apexpages.devmode.url=1
Fri, 11 Nov 2011 07:41:43 GMT 7 : ID=83030 *SCRIPT* rf_sendMessageToBG. CS -> BGO : cmd:clearCS g_docnum:7100382
Fri, 11 Nov 2011 07:41:44 GMT 38 : ID=83030 *SCRIPT* rf_CS_receiveBG. COMMAND=setdocnum
Fri, 11 Nov 2011 07:41:44 GMT 39 : ID=83030 *SCRIPT* rf_CS_receiveBG g_docnum=1 Also eval language localization data

 

Chirag MehtaChirag Mehta

@Pat @VM_SFDC - Any advise on why it's not working?

Pat PattersonPat Patterson

Hi Chirag,

 

I've seen these kind of errors when using outdated versions of the CometD libraries - ensure you download version 2.2.0 as detailed at http://wiki.developerforce.com/page/Getting_Started_with_the_Force.com_Streaming_API#Receiving_Notifications_in_a_Visualforce_Page

 

Note also that I just made a couple of unrelated minor corrections to the VF page there - I noticed that the update data was not being correctly shown. After you get CometD 2.2.0, update your VF page, ensure you have created a PushTopic, and all should work.

 

Cheers,

 

Pat

Chirag MehtaChirag Mehta

I'm using version 2.2.0 and also updated the VF code as mentioned @ http://wiki.developerforce.com/page/Getting_Started_with_the_Force.com_Streaming_API#Receiving_Notifications_in_a_Visualforce_Page, yyet it's resulting in error.

 

 

 

Pat PattersonPat Patterson

It's very strange - the errors seem to be in the CometD/jQuery scripts before any of the JS in the VF page actually runs. If you PM me your username/password for the org, I can log in and take a look.

 

Cheers,


Pat

Pat PattersonPat Patterson

Hi Chirag,

 

I see the problem - you've used

 

cometd-2.2.0/cometd-javascript/common/src/main/js/org/cometd/Cometd.js

as the cometd static resource, rather than

 

cometd-2.2.0/cometd-javascript/common/target/org/cometd.js

I remember now, I fell into the same trap the first time - cometd.js is now assembled from several JS files, one of which is, confusingly, Cometd.js.

 

If you don't see the cometd.js file in common/target/org/, you just need to unpack the war file, as mentioned in the article:

 

$ cd cometd-2.2.0/cometd-javascript/common/target
$ jar xvf cometd-javascript-common-2.2.0.war org/cometd.js

 

Cheers,

 

Pat

Chirag MehtaChirag Mehta

Unpacked the war file and updated my comted static resource with unpacked cometd-javascript-common-2.2.0\org\cometd.js. 

 

Yet it's showing below errors:

Uncaught SyntaxError: Unexpected token ILLEGAL chiragmehta__jquery_cometd:107

Uncaught ReferenceError: jQuery is not defined StreamingPage:126

Uncaught TypeError: Cannot call method 'init' of undefined StreamingPage:118

Uncaught TypeError: Property 'oldOnLoad' of object [object DOMWindow] is not a function

Pat PattersonPat Patterson

Hi Chirag,

 

I went in again and spotted a few remaining issues:

 

1. The jquery static resource was a zip instead of a JS file - I added jquery_pat as a JS file.

 

2. Some of the customizations in your sidebar are interfering with the streaming sample - these are the errors I was seeing:

 

$.cometd is undefined
Stream...e.url=1 (line 130)
oldOnLoad is not a function
</div></div><div class="sidebarModule ...Bin</span></a></div></div></div></td> 

Adding sidebar="false" to the VF page definition fixed these.

 

3. The notification handler in the VF page needed a little update to correspond to the 23.0 notification structure (bringing it inline with the current wiki page).

 

All is working now! Here is a screen cap from your apex/StreamingPage

 

 

Cheers,


Pat

Chirag MehtaChirag Mehta

That's super awesome, and thanks a lot for all your support and co-operation. I mean it!

 

Just one gentle request - lets update all these points of (the war point, dont upload zip, and the version 23.0) in the wiki article, so that in future people are able to create the streaming sucessfully on very first attempt.

 

Thanks again!

Pat PattersonPat Patterson

Hi Chirag,

 

I actually went in and did that a few days ago - http://wiki.developerforce.com/page/Getting_Started_with_the_Force.com_Streaming_API#Receiving_Notifications_in_a_Visualforce_Page - it explains how to unpack the war, and the files to copy as static resources. Not sure about your version 23.0 point.

 

Cheers,

 

Pat

Jitendra Zaa.ax1186Jitendra Zaa.ax1186

Hi ,

I have written step by step article to implement streaming API and how to debug using firebug in case it fails at "http://shivasoft.in/blog/others/tips/streaming-api-using-jquery-salesforce/".

 

Pat PattersonPat Patterson

Nice article, Jitendra - I just tweeted it - https://twitter.com/metadaddy/status/199542823069040640 :-)

Chirag MehtaChirag Mehta
Nice one Jitu! I was able to create one great use case of streaming api, check out @ http://www.chiragmehta.info/chirag/2012/04/14/chatter-stream-or-chatter-ticker/
Tech ThirstsTech Thirsts
Thanks to this thread! Saved me a lot of time! :)
Prakash@SFDCPrakash@SFDC
I am trying to download JSON.org Java file to implemet this from JAVA , but that file URL is not exist . It is showing " The document name you requested (/java/json.zip) could not be found on this server ". Can somebody help me how to get this file ?
Mahesh Kumar 287Mahesh Kumar 287
For all streaming query just visit https://www.allstreamingsites.com (https://www.allstreamingsites.com/) .Check out the websites using streaming API and using video from different websites.
Raguraman Selvaraj 5Raguraman Selvaraj 5
Hi Chirag, 
I need your assistance below.
I have created platform event and trying to subscribe through visualforce page. I am getting below mentioned errors.

12:53:38.271 Appending message type to URI /cometd/49.0/ is not supported, disabling 'appendMessageTypeToURL' configuration
jQuery:4055 Uncaught Illegal state: handshaken
(anonymous) @ jQuery:4055
setTimeout (async)
jQuery.readyException @ jQuery:4054
(anonymous) @ jQuery:4074
mightThrow @ jQuery:3762
process @ jQuery:3830
setTimeout (async)
(anonymous) @ jQuery:3868
fire @ jQuery:3496
fireWith @ jQuery:3626
fire @ jQuery:3634
fire @ jQuery:3496
fireWith @ jQuery:3626
process @ jQuery:3850
setTimeout (async)
(anonymous) @ jQuery:3868
fire @ jQuery:3496
fireWith @ jQuery:3626
fire @ jQuery:3634
fire @ jQuery:3496
fireWith @ jQuery:3626
ready @ jQuery:4106
completed @ jQuery:4116
cometd:885 WebSocket connection to 'wss://awr--raguramans--c.visualforce.com/cometd/49.0/' failed: Error during WebSocket handshake: Unexpected response code: 405
_websocketConnect @ cometd:885
_send @ cometd:1002
WebSocketTransport._self.send @ cometd:1157
_send @ cometd:1646
_handshake @ cometd:1862
CometD.handshake @ cometd:2540
CometD.init @ cometd:2527
(anonymous) @ LeadPlatformEvent:19
mightThrow @ jQuery:3762
process @ jQuery:3830
DevTools failed to load SourceMap: Could not load content for https://awr--raguramans--c.visualforce.com/javascript/1592237695000/sfdc/source/main.js.map: 

Visual page code:

<apex:page >
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Page
  <!-- End Default Content REMOVE THIS --> <div id="content">
        
    </div>
    <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">
    (function($){
        $(document).ready(function() {
     $.cometd.init({
    url:  window.location.protocol+'//'+window.location.hostname+'/cometd/49.0/',
    requestHeaders: { Authorization: 'OAuth {!$Api.Session_ID}'}
});        

            $.cometd.handshake();
            $.cometd.addListener('/meta/handshake', function(message) {
                $.cometd.subscribe('/event/Event_On_Leads__e', function(message) {
                
                    console.log('testing subscribed');
                    var div = document.getElementById('content');
                    
                    div.innerHTML = div.innerHTML + '<p>Notification </p><br/>' +
                        'Streaming Message ' + JSON.stringify(message) + '</p><br>';
                });
            });
            
        });
    })(jQuery)
    </script>

</apex:page>