Bad Value For Restricted Picklist Field Deployment Error

I recently came across a scenario where I needed to deploy some triggers that use a new picklist field that was defined as “restricted.” In the sandbox, the triggers were working great and the test classes were covering 99% of the code. Easy, right? It should’ve been…

During the deployment, my test classes were failing. “System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, bad value for restricted picklist field” etc etc.

I double, triple, and quadruple checked the value being set by the code, added some debug statements, and even took a small walk outside the office thinking that I simply needed more blood flow to my brain because I was missing something so simple and rudimentary.

Come to find out, there was nothing wrong with my code and I didn’t miss any components in the deployment. There is a Salesforce bug with deploying a restricted picklist field with code that tests it in the same deployment!

There are 2 workarounds that I have found:

1. Deploy the field first and then deploy the code separately. 2. Uncheck the “Strictly enforce picklist values” option in sandbox, deploy the field and code in the same deployment, then re-check “Strictly enforce picklist values” option in production.

I have not seen this bug reported in Known Issues. I may just do that now. Hopefully this blog will help prevent you from spending too much time on a simple deployment.

Happy coding!