For Developers

September 23, 2016

Bad Value For Restricted Picklist Field Deployment Error

John Pipkin

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!

About the Author

John Pipkin

John is a Senior Developer at OpFocus. John specializes in Apex, Visualforce, integrations, jQuery, Visual Flows, and Lightning Processes, but particularly enjoys the power to customize pretty much anything on the Salesforce platform. When he is not working his magic on the platform, John enjoys creating musical magic, and plays the drums and guitar. Since he's a total rock star, John has 11+ Salesforce Certified designations. Go through this list if you want to feel immensely inadequate about your Salesforce skills... Administrator (201), Platform App Builder, Developer (401), Platform Developer I, Sales Cloud Consultant, Service Cloud Consultant, Community Cloud Consultant, Mobile Solution Architecture Designer, Integration Architecture Designer, Development Lifecycle & Deployment Designer, Identity & Access Management Designer, and System Architect certifications.

Related Posts