We are trying to track the duration (time spent in days/hours) in each Status change (Custom Field) on the Opportunities Object. Right now we have enabled field history on this custom field (picklist) of status, but this reports into the Opportunity Field History related box (which shows changes made to anything altered in the Opportunity)

We need to only track the Change of Status on this picklist and how much time it spent total in that particular status.

So, if the User A creates the Opp in status "New". User B changes it one day later to Status "In Progress" and then User C changes it one day later to Status "New" again. Finally User D sets the status to "Completed" one day later. What should show on the table. As I coded it, this is what should show: Status = Time in Status (days) --------------- New = 2, In Progress = 1, Completed = 1

In this ie: History should show: Last Modified By Column 'User A' Status Column 'New' Total Duration 2 days Last Modified by Column 'User B' Status Column 'In Progress' Duration 1 day etc

Currently using this code attached below but need to know How can we change 'Opportunity Status Change Name' from displaying those random sequence of numbers and letters to the actual name of the stage?enter image description here

enter image description here

  • What's the field name for the picklist that contains the Stage Names in your Custom Object or are you talking about Opportunity.StageName which you can get from Opportunity or OpportunityHistory?
    – crmprogdev
    Commented May 28, 2015 at 15:13
  • The name of the picklist is 'Operations Status' under the Opportunity object
    – JazzyJ
    Commented May 28, 2015 at 15:36
  • I'm confused then as to why your trigger isn't firing on OpportunityHistory rather than this Custom Object OR why your Custom Object isn't grabbing the value of OperationsStatus when a change occurs. A picklist is merely a string of text and you can always get the previous and current value from trigger.old and trigger.new.
    – crmprogdev
    Commented May 28, 2015 at 15:44

3 Answers 3


All objects in Salesforce have to have a Name value and if you do not provide one when creating the objects via code it defaults to the Id of the object, that is what you are seeing with the "random" string of characters. If you want the name to be your stage name then when you are creating the Opportunity Status Change Object just make Name = whatever value you want. In this case I think it is your status field.


Like @CyberJus suggested, setting Name in the code using the Status value is probably the way to go. You could also just drop the Status field from the related list and layout and copy the Status to Name using a Workflow rule.

The fields @James suggests can be a way to do this, but breaks down after more than a few Status values, and you need to think long and hard about all the rules. Can you skip statuses/is a linear workflow enforced/can you go backwards? If it's not clear which fields need to be used in the calculations consistently, you can have some problems. I also believe that the history tracking object gives more robust reporting capabilities if a little more complex for end users.

For Lead Status, I really like a free AppExchange product. It takes a similar approach that you are with the custom object. It may be worth looking at to compare your solution and give you some ideas on making it more bulletproof.


I would recommend moving away from your code-based solution.

I suggest creating several custom fields to support this, coupled with Workflow.




From here, you can create workflow rules which will update the appropriate field with a date/time stamp (CreatedDate is implicitly Stage 1 Begin Date). Once you have the values, you can easily create custom formula fields to determine differences between the stage changes, which will yeild your sought-after "Stage Duration."

This, will make your date reportable and much easier to understand/maintain. Note, you'll have to go back and add the datestamps to historical data...

You must log in to answer this question.

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