
Bad value for restricted picklist field
In Salesforce, when picklist fields are defined with a set list of selected values, the option to select ‘Restrict picklist to values defined in the value set’ checkbox is available for us to check. This checkbox is unchecked by default and one must check it to enable this feature.
What is the use of ‘Restrict picklist to values defined in the value set’ checkbox?
This checkbox is used to restrict the use of the picklist field to the values defined by the salesforce administrator or developer when a record is created or updated either manually or via automation (scripts or API calls etc).
What is better – Restricted vs unrestricted picklist Salesforce?
It is always better to restrict picklist values for better data quality and integrity. Otherwise, reporting on data will show inconsistent and rubbish values.
Errors that can occur due to picklist value restriction
The following errors may occur to users when data is being added to the picklist field that is not a part of the restricted and defined set of picklist values for a field.
- ‘bad value for restricted picklist field: PicklistValue’
- INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST
Error Causes
- The referenced picklist field has ‘Restrict picklist to the values defined in the value set‘ set to Enabled.
- The referenced picklist field is a dependent picklist.
- The page layout does not include both the controlling and dependent picklist fields.
- A default value is set for the referenced picklist field:
- If the object includes Record Types – This error occurs if the record type sets the default value.
- If the object does not include Record Types – This error occurs if the picklist field sets the value.
- All record types should have the newly create picklist selected in the Selected items section and not under available items.
- Initiate a Mass Quick Action with Predefined Value Set
- Any active trigger on the object where the field is used can give the same error.
- This error can occur when you deploy a picklist field from sandbox and the values are not selected on the record types.
- This error can occur when the value ‘Label’ and ‘API Name’ are different in the values, and you use the ‘Label’ name in the update.
Note: above snippet is from this Salesforce article.
How to fix ‘Bad value for restricted picklist field’ error
The simplest way to fix this error is by unchecking the ‘Restrict picklist to the values defined in the value set‘ checkbox on the picklist field itself. However, as mentioned above this may cause data integrity issues.
There are also times that the main cause can also be the default value of the picklist field that is set on the record type.
To resolve this issue, remove the default value from the Record Type or picklist field (depending on where it is set).
Remove the default value: Record Type
- Select the gear icon | Setup.
- Click Object Manager.
- Select the object for the record type that contains the picklist.
- Select Record Types.
- Select the record type that contains the picklist.
- Click Edit for the picklist you wish to change.
- In the ‘Default’ field, select –None–.
- Click Save.
Remove the default value: Picklist
- Select the gear icon | Setup
- Click Object Manager.
- Select the object that contains the picklist.
- Select Fields and Relationships.
- Select the picklist field you wish to change.
- Click Edit for the picklist value that is set as the Default.
- Deselect the ‘Default’ checkbox. Note: Make this value the default for the master picklist.
- Click Save.
Conclusion
As stated above, there is always a reason why picklist values are restricted or defaulted to a certain value, so it is best to fix the code where the exception is happening by catching and handling the error. This article is a useful guide on how to handle exceptions in Apex.