0

We want to have Visualforce page with events displayed publicly. What is the best way to trigger Visualforce refresh when data is updated/inserted/deleted in the custom object directly through the Salesforce.

One way suggested is to have a timer, and check data every hour or so (e.g. ajax call), and if data is changed, then refresh the page and retrieve new data with changes.

But, by any chance, is there any way to invalidate all Visualforce pages (sessions ? ) and force them to reload when data is changed?

1

1 Answer 1

2

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.

enter image description here

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

1
  • Is it reasonable to use for the publicly accessible webpage with list of current events? Which can be updated twice a day ?
    – vlr
    Commented Sep 6, 2016 at 6:55

You must log in to answer this question.

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