You need to sign in to do that
Don't have an account?
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
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)
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
Even after following the updated wiki article, the VF page shows nothing and the console says "Uncaught error"
Chrome JS console says
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'"
@Pat @VM_SFDC - Any advise on why it's not working?
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
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.
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
Hi Chirag,
I see the problem - you've used
as the cometd static resource, rather than
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:
Cheers,
Pat
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
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:
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
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!
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
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/".
Nice article, Jitendra - I just tweeted it - https://twitter.com/metadaddy/status/199542823069040640 :-)
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>