February 12, 2012

Salesforce streaming API and Chrome desktop notifications

I likeimage chrome desktop notifications a lot, they specially help me with gmail running in browser always and keeping me updated about new mails/chats without keeping the gmail tab open. I also like the way gmail desktop notifications in chrome take to the email related with the notification, again saves time and clicks.

Salesforce PushTopic Desktop Notifications

I wanted something similar with Force.com Streaming API or the PushTopic notifications. If you are working on a crucial Campaign, Account, Lead or Opportunity, then instead of waiting for chat/email/phone for updates, one can setup PushTopics and get updated in close to real time using “chrome desktop notifications”. Something like this:
image

Notifications experiment !

Regarding the same, I tried a small experiment to use Salesforce streaming API (PushTopics) with Chrome Desktop Notifications. The initial fixture I created was clone of visualforce code sample available in streaming api docs.
Here is a demo video that shows the force.com desktop notifications in action (Watch it Full Screen for better visibility)
Here is the full source of the visualforce page “streamingnotifications” : https://gist.github.com/1808548
You will also need to
  • download and setup comet static resources as indicated in the Streaming API guide.
  • replace the images being served from my dropbox folder with yours.
  • This page is designed keeping Account sobject notifications in mind, so please setup PushTopics as required. The one I used was created using this apex code
    PushTopic pushTopic = new PushTopic();
    pushTopic.Name = 'AccountUpdates';
    pushtopic.Query = 'SELECT Id, Name, Phone, Fax  FROM Account'; 
    pushTopic.ApiVersion = 24.0;
    pushTopic.NotifyForOperations = 'All';
    pushTopic.NotifyForFields = 'Referenced';
    insert pushTopic; 

Possibilities Streaming PushTopics & Chrome Desktop notifications ?

One can use chrome desktop notifications in very interesting ways. Few ideas I can think of are
  • Embed this visualforce page and embed it into the home page layout, so that user doesn’t need to browse anywhere.
  • Show list of PushTopics available in the VF page to user, and let user select the ones he is interested in. Notifications would be shown only for those PushTopics. This page should also have option to stop notifications about a particular topic.
What other PushTopics can be helpful ?
  • Chatter : Create a push topic with query on required Feed like NewsFeed, so that anything relevant to chatter is also showed in desktop notifications.
  • Leads/Opps : If team is working on same lead/opp they don’t need to refresh the page, or wait for email/call/chat to know about the important changes.

Note about PushTopics security & Limits

Security is well implemented on PushTopics, but its important to understand before setting up the expectations.
Here is what I found from the Streaming API developer guide about Security
Subscribers receive notifications about any create or update to a record if they have:
• Field-level security access to the fields specified in the WHERE clause
• Read access on the object in the query
• Visibility of the new or modified record based on sharing rules
If the subscriber doesn’t have access to specific fields referenced in the query SELECT clause, then those fields aren’t included in the notification. If the subscriber doesn’t have access to all fields referenced in the query WHERE clause, then they will not receive the notification.
Equally important is to know the Limits of Streaming API.
image