I have a trigger on the Opportunity object and am required to process the record in the trigger if the opportunity stage is at a specific value or later in the sales process.

new -> quoting -> negotiation -> signature -> closed won

if the stage is at the "negotiation" stage or later it should be processed.

The only way I can think to do this is by hardcoding the stage values for each sales process and seeing if the current stage is in that set.

But this is problematic if more stages are added later.

I also thought about comparing the stage's probability and if the current opportunity is >= the probability process. But this is also problematic because opportunity probability can be changed manually.

Is there a "Best Approach" to this problem?

2 Answers 2


Thanks to List.indexOf (new in v42.0), you can do something like this:

String[] stages = new String[0];
for(PicklistEntry value: Opportunity.StageName.getDescribe().getPicklistValues()) {
for(Opportunity record: Trigger.new) {
  if(stages.indexOf('Negotation') <= stages.indexOf(record.StageName)) {
    // Do something here

A map is slightly more efficient if you have a of stages, though:

Map<String, Integer> stages = new Map<String, Integer>();
Integer index = 0;
for(PicklistEntry value: Opportunity.StageName.getDescribe().getPicklistValues()) {
  stages.put(value.getValue(), index++);
for(Opportunity record: Trigger.new) {
  if(stages.get('Negotation') <= stages.get(record.StageName)) {
    // Do something here
  • What order does Opportunity.StageName.getDescribe().getPicklistValues() return the values in? The documentation doesn't say if it returns the values in the order of the sales process Commented Feb 7, 2018 at 22:41
  • @Programatic The documentation doesn't say it explictly, but it's the order of the list. See this question.
    – sfdcfox
    Commented Feb 7, 2018 at 22:44
  • Oh, that's more elegant than the answer I posted (I was working on it when you posted yours!) Commented Feb 7, 2018 at 23:16

Here's how to dynamically get a list of the stagenames:

Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
List<String> StageNames = new List<String>();
for(Schema.PicklistEntry s:ple){


From there, you can get the index of "Negotiation" or whatever field you want, then set up a loop going from that index + 1 to StageNames.length() - 1 to build a list of stages after negotiation.

Then, just check to see if the current stageName is in the list of stages after negotiation.

Hope that helps.

You must log in to answer this question.

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