Wednesday, 3 April 2013


Opportunity Close Date: Push Counter

It is often desirable to be able to understand, at a glance, just how many times a certain activity has happened. One common example of this is the Opportunity Push Counter. Sales management always finds it very useful to know how many times the sales rep has "pushed" the Opportunity off, generally into a new quarter. (Forecasts cannot be trusted if the deal being forecast keeps getting shuttled from quarter to quarter.) There are tons of examples around - here's mine.First, we start off by creating two fields on the Opportunity object:
  • Push_Count__c - Number(10, 0), defaulted to 0
  • Push_Counter__c - Formula(Text)
We hide the Push Count field, which is populated automatically via trigger, and show the Push Counter field. This formula takes the Push Count and outputs a horizontal bar graph that displays the relative severity of the problem for this Opportunity. Here's one push:
And here's four pushes:

And here's seven pushes:

As you can see, the color and magnitude of the image graphically shows the magnitude of the issue in a way that both sales management and sales reps cannot ignore. (As the number of pushes goes up, the size of the bar does too.)
Here's the formula field, using techniques discussed last year:

IF(AND(Push_Count__c >= 0,Push_Count__c <= 2), 
   IMAGE("/img/samples/color_green.gif", TEXT(Push_Count__c) + ' Pushes', 
   14, (Push_Count__c + 1) * 10),
IF(AND(Push_Count__c >= 3,Push_Counter__c <= 5), 
   IMAGE("/img/samples/color_yellow.gif", TEXT(Push_Count__c) + ' Pushes', 
   14, (Push_Count__c + 1) * 10),
IF(AND(Push_Count__c >= 6,Push_Counter__c <= 9), 
   IMAGE("/img/samples/color_red.gif", TEXT(Push_Count__c) + ' Pushes', 
   14, (Push_Count__c + 1) * 10),
IMAGE("/img/samples/color_red.gif", 'Too Many Pushes', 14, 100))))
(I had to break up the formula to get it to display here. You'll need to join it back together.)
And here's the trigger:

// ==================================================================================
//   Object: biuOpportunity
//   Author: John Westenhaver
// Comments: Automatically increment a counter every time the Close Date changes.
// ==================================================================================
//  Changes: 2011-09-14 Initial version.
// ==================================================================================

trigger biuOpportunity on Opportunity (before insert, before update)
{
   if (system.trigger.isInsert)
   {
      for (Opportunity o : system.trigger.new)
      {
         o.Push_Counter__c = 0;
      }
   }
   else
   {
      for (Opportunity o : system.trigger.new)
      {
         // If the Close Date has changed,
         // and the new Close Date is after 
         // the old Close Date, then increment
         // the "push" counter.
         if (o.CloseDate != null &&
            system.trigger.oldMap.get(o.Id).CloseDate != null &&
            o.CloseDate > system.trigger.oldMap.get(o.Id).CloseDate)
         {
            o.Push_Counter__c += 1;
         }
      }
   }
}
You can easily extend this concept to other fields and objects by making trivial changes to this code.
Categories:

0 comments:

Post a Comment

    Links