Created
October 24, 2013 16:52
-
-
Save sbob909/7140890 to your computer and use it in GitHub Desktop.
Force.com Visualforce page code sample: Streaming API page for openInvoices to support Building Efficient Visualforce Pages workshop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page showHeader="true" controller="invoiceController" tabstyle="Invoice__c" 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"> | |
(function($){ | |
$(document).ready(function() { | |
$.cometd.init({ | |
url: window.location.protocol+'//'+window.location.hostname+'/cometd/24.0/', | |
requestHeaders: { Authorization: 'OAuth {!$Api.Session_ID}'} | |
}); | |
$.cometd.subscribe('/topic/openInvoices', function(message) { | |
var invoice = message.data.sobject; | |
var thisEvent = JSON.stringify(message.data.event.type); | |
var data = {'Id':invoice.Id,'Name':invoice.Name}; | |
console.log(data); | |
console.log(thisEvent); | |
var newhtml = '<apex:pageBlock ><p>Invoice <a href="../'; | |
newhtml = newhtml.concat(data.Id,'">', data.Name, '</a> just ', thisEvent, '. </p></apex:pageBlock>'); | |
console.log(newhtml); | |
$('#content').append(newhtml); | |
}); | |
}); | |
})(jQuery) | |
</script> | |
<body> | |
<div id="content"> | |
<h1>Recent Open Invoices</h1> | |
</div> | |
</body> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment