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
Mike A SmithMike A Smith 

Is it possible to restrict picklist access on record creation?

Hi,

Is is possible to restrict access to a picklist on record creation with a VR? Meaning if only certain users are allowed to create a NEW record with any of the values in a certain PL can this be done with a VR or is a trigger needed?

Thanks.
Best Answer chosen by Mike A Smith
VinayVinay (Salesforce Developers) 
You can something like below validaton.
 
AND(
ISNEW(),
OR(ISPICKVAL(fieldname,'Sandbox A'), ISPICKVAL(fieldname,'Sandbox B')),
OR($User.Username = 'username1', $User.Username = 'username2'),
ISCHANGED(picklist field)
)

Please mark as Best Answer if above information was helpful.

Thanks,

All Answers

VinayVinay (Salesforce Developers) 
Hi Mike,

You can try below trigger.
 
trigger restrict on Objectname__c (before insert) {
    if(trigger.IsBefore && trigger.IsInsert){
        for(Objectname obj:trigger.new){
            if(obj.pickval__c == 'test'){
                obj.pickval__c.addError('Cant select this picklist value');
            }
        }
    }
}

Please mark as Best Answer if above information was helpful.

Thanks,
Mike A SmithMike A Smith
Thanks Vinay. So a VR is definitely NOT an option here to prevent record creation based on a PL selection correct?
VinayVinay (Salesforce Developers) 
Try below validation and let me know if you see any issues.
AND(ISNEW(), ISPICKVAL(fieldname,'test lov'))

Hope this helps...

Thanks,
Mike A SmithMike A Smith
Thanks Vinay. What if it's a Picklist like below and I want to restrict access to specific users on BOTH record creation AND any future edit on an existing record... possible in a VR?

Sandbox access;
  Sandbox A
  Sandbox B
 
VinayVinay (Salesforce Developers) 
You can something like below validaton.
 
AND(
ISNEW(),
OR(ISPICKVAL(fieldname,'Sandbox A'), ISPICKVAL(fieldname,'Sandbox B')),
OR($User.Username = 'username1', $User.Username = 'username2'),
ISCHANGED(picklist field)
)

Please mark as Best Answer if above information was helpful.

Thanks,
This was selected as the best answer
Prateek Prasoon 25Prateek Prasoon 25
Yes, it is possible to restrict access to a picklist on record creation using a validation rule in Salesforce. You can create a validation rule on the object and define the criteria to check if the user has the required permission to select the picklist value.
For example, let's say you have a picklist field called "Status" with the values "Open" and "Closed". You only want users with the "Sales" profile to be able to select the "Closed" value. To achieve this, you can create a validation rule on the object with the following formula:
AND(
  ISNEW(),  // check if it's a new record
  $Profile.Name <> "Sales",  // check if user's profile is not "Sales"
  ISPICKVAL(Status, "Closed")  // check if the "Closed" value is selected
)

This validation rule will prevent users who are not in the "Sales" profile from creating a new record with the "Closed" value selected in the Status picklist.
Note that validation rules only run when a record is saved, so users may still be able to select the restricted picklist value, but they will receive an error message when they try to save the record.
If you want to prevent users from even seeing the restricted picklist values, you may need to use a trigger to enforce the restriction.

If you find my answer helpful, please mark it as the best answer. Thanks!
Mike A SmithMike A Smith
Hi Vinay,

Thanks for the answer on 4/25. I was able to restrict the picklist option to certain users using your formula but what I need to do is prevent the restricted users from updating the picklist after the record is created. Possible to do in the same VR?

So if my picklist has options 'Sandbox A' and 'Sandbox B'... the users who CANNOT now select and save with 'Sandbox A' when creating the new record can select 'Sandbox B' and save it .... but then they can immediately edit that PL on the new record and select 'Sandbox A' and save it.

Is it possible to add more to the formula on the VR to prevent the user from selecting the restricted option AFTER the record is created?

Thanks,

Mike
VinayVinay (Salesforce Developers) 
Hi Mike,

Sure, can you please post as an new question and add details over there so that I can review and update.

Thanks,
Mike A SmithMike A Smith
Ok done, thanks Vinay. id=9062I000000DPUK