Monday, 6 April 2015

Navigation made easy with Lead Notifier

It’s that time of the year when the air is full of performance reviews. Appraisal cycles are in full bloom and the managers are on a prowl! Every employee is seen making his best attempts to impress his manager, hopeful of getting a bigger chunk of the delicious pie called performance bonus and I was no saint either! But impressing my manager was no easy job! What is it that I could do? I probably needed something as path breaking as a time machine!


I thought and thought hard. I realized I had the power of Salesforce and I felt like a rock star! My plan was beginning to shape up now. Let me give you a sneak peek!

I realized that most Sales Reps in my organization ended up spending a huge chunk of their time navigating back and forth, from their Salesforce screens to monitor the new incoming Leads. This navigation was a big no-no as far as productivity was concerned and monitoring new leads was becoming increasingly difficult for them. “Why is that a big deal? You have Queues, Assignment rules and emails for Lead Management!” I hear you say. However, ours was a Salesforce instance that had just started out. And I needed to do something about it!

The Game Plan!

My game plan was built on a simple fact: The user should be notified whenever a new lead is generated, irrespective of which tab he was navigating on: home or elsewhere within the application.

The solution involved using a combination of Apex and Visualforce but the secret component of my solution plan was to leverage the Home Page and Sidebar components. Let me show you how I did it in a few simple steps!
  1. First, I created a simple Visualforce page using the code snippet given below. I call it the Lead Notifier Page.

    Apex Code

    Visualforce Code

    The Visualforce code leveraged the standard < apex:actionPoller > which enabled auto refresh, thus facilitating the lead notifier to pick up the newly created Lead information in real time.

  2. Once this was done, I modified the home page component and added the Lead Notifier Page created in step 1, so that it started appearing on the Home page.

  3. I went on to modify the sidebar component to add the Lead Notifier Page created in step 1, so that it started appearing on the Home page.

    Finally, this is how my Home page looked like.

There! I had nailed it! My Sales Reps were absolutely loving it! Needless to say, I got a few brownie points from them when they put in a favourable word to my boss. As for me, I was simply glad I had Salesforce to rely on, no matter what!

Written by Jigar Shah, Solution Architect at Eternus Solutions


  1. Jigar - I came across your lead notifier blog post. Very good information.

    One question I had was, what might be needed to only show the leads open by logged user?

    Sale rep 1 logs, it would show his leads only. Sales rep 2 logs in and shows his leads, etc.

    Any input would be helpful.

  2. Chris, assuming that the Lead's Owner field value is set to the Logged in User and the Org Wide Default setting for Lead n your Salesforce instance is set to Private you will not need to do anything explicit. The existing code will get you the Open leads in the context of the logged in User.

    However, if the mentioned settings don't hold true then modify the query from the getOpenLeadsCount() to "Select COUNT() From Lead Where Status ='Open' And OwnerId = Userinfo.getUserId() ". Let me know if that helps !

  3. This comment has been removed by the author.

  4. Getting an error b/c I'm not sure how to update with your new code.

    // Refresh number of leads
    public PageReference leadCountAutoRefresh() {
    countValue = getOpenLeadsCount();
    return null;

    // Returns number of leads with status Open
    private Integer getOpenLeadsCount() {
    return [Select COUNT()From Lead Where Status = 'Open' Userinfo.getUserId()];

    }//LeadCountNotifierController ends

  5. @nalec7 you are missing the "AND OwnerId = :Userinfo.getUserId()" in your query.

  6. That was it. Thank you so much for the help and idea.