The Force.com Streaming API lets you expose a near real-time stream of data from the Force.com platform. Administrators can create topics, to which applications can subscribe, receiving asynchronous notifications of changes to data in Force.com, via the Bayeux Protocol. Streaming data made simple, secure, and scalable.
You can follow below steps
Step 1: Create an Object - Account
Step 2: Create PushTopic
PushTopic pushTopic = new PushTopic();
pushTopic.ApiVersion = 23.0;
pushTopic.Name = 'AllAccounts';
pushTopic.Description = 'All records for the Account object';
pushtopic.Query = 'SELECT Id, Name FROM Account';
insert pushTopic;
System.debug('Created new PushTopic: '+ pushTopic.Id);
Step 3: Create Static resource from following file http://download.cometd.org/cometd-2.2.0-distribution.tar.gz
Step 4: Create visualforce page
(function($){
$(document).ready(function() {
// Connect to the CometD endpoint
$.cometd.init({
url: window.location.protocol+'//'+window.location.hostname+'/cometd/23.0/',
requestHeaders: { Authorization: 'OAuth {!$Api.Session_ID}'}
});
// Subscribe to a topic. JSON-encoded update will be returned
// in the callback
$.cometd.subscribe('/topic/AllAccounts', function(message) {
$('#content').append('Notification: ' +
'Channel: ' + JSON.stringify(message.channel) + '
' +
'Record name: ' + JSON.stringify(message.data.sobject.Name) + '
' +
'ID: ' + JSON.stringify(message.data.sobject.Id) + '
' +
'Event type: ' + JSON.stringify(message.data.event.type)+'
' +
'Created: ' + JSON.stringify(message.data.event.createdDate) + '
');
});
});
})(jQuery)
<div id="content"><p>notification will appear here</div>
Ref : https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_Streaming_API