[SalesForce] Enforcing Order of Execution (stage progression) in picklist

How to force the order of execution(selection) of the picklist values in salesforce.Is there any other way other than validation rules in visualforce page.

Lets say I have 4 picklist values (Draft,Rep Input,Rep Ack,Completed) on Status field.I want to force the users to go through each stage before it gets to 'Completed' status.

The process is similar to opportunity stage

Best Answer

The enforcement of stage progression is most easily done using validation rules with the ISCHANGED and PRIORVALUE functions. The validation rule will enforce stage progress based on the current and prior picklist value.

This example validation rule should enforce the progress from Draft to Rep Input to Rep Ack to Completed and nothing is allowed to be reverted back to Draft status. (The first AND from "not draft" to "draft" might need to be altered to handle a blank value, but it demonstrates the idea.)

As Mike noted in his answer, this methodology only forces the user to save the record multiple times with picklist values in a specific order - it doesn't truly enforce anything. Though maybe this is exactly what you're looking to do here.

One thing to note, this is not just a VF solution. It works in all cases - VF, native pages, data loader, batches, etc. since it's enforced at the record level when the database commit takes place.

Error Formula

AND(
    ISCHANGED( Status ),
    OR(
        AND(
            NOT(ISPICKVAL( PRIORVALUE( Status ), "Draft" )),
            ISPICKVAL( Status, "Draft" )
        ),
        AND(
            NOT(ISPICKVAL( PRIORVALUE( Status ), "Draft" )),
            ISPICKVAL( Status, "Rep Input" )
        ),
        AND(
            NOT(ISPICKVAL( PRIORVALUE( Status ), "Rep Input" )),
            ISPICKVAL( Status, "Rep Ack" )
        ),
        AND(
            NOT(ISPICKVAL( PRIORVALUE( Status ), "Rep Ack" )),
            ISPICKVAL( Status, "Completed" )
        )
    )
)