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
andPRIORVALUE
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
toRep Input
toRep Ack
toCompleted
and nothing is allowed to be reverted back toDraft
status. (The firstAND
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