function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RobRRobR 

Picklist Validation?

Hello, I am trying to validate a picklist. I would like the users to only be able to select the next value in the list.

 

e.g.

 

Picklist:

Stage 1

Stage 2

Stage 3

Stage 4

 

I only want the user to be able to select "stage 1" save the record, The only be able to select "Stage 2" save the record... ect..  Is this possible?

 

Thanks

gotherthanthougotherthanthou

If this is possible via a validation rule, it will be long, complicated, difficult to troubleshoot.

 

You should be able to do this fairly easily with a trigger.  The following is air code; I did not actually try to compile it but it should get you started.

 

 

trigger CustomObjectTrigger on CustomeObject__c (before insert, before update) { for (Integer i = 0; i < Trigger.new.size(); i++ ) { if (Trigger.isInsert) if (Trigger.new[i].Stage != 'Stage 1') Trigger.new[i].Stage.AddError('Must Be created Stage 1'); if (Trigger.isUpdate) { if ((Trigger.old[i].Stage == 'Stage 1') && (Trigger.new[i].Stage != 'Stage 1' && Trigger.new[i].Stage != 'Stage 2') Trigger.new[i].Stage.AddError('Must Create Stages in Order'); etc, etc, etc } } }

 

 

 

RobRRobR

Thank you very much for your reply. I have taken a look at your code but i'm new to SF, could you let me know where I would apply this?

 

Thanks

gotherthanthougotherthanthou
[Setup][App Setup][Create][Objects] Pick the object with the Stage field.  Scroll down to the triggers section and hit New.
RobRRobR
I have naviagted there but I dont have any option to create a new triger. All I get is "No triggers defined" 
gotherthanthougotherthanthou
I'm just guessing here, but you're probably logged in as user whose profile does not have the 'Author Apex' checkbox checked under Administrative permissions.  If that's not it I'm clueless.