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
Mario BravoMario Bravo 

Restricted Picklist Value

Hi devs!
I'm having a problem when assigning a value into a custom field in a custom object. The error message is the following:
Line: 6, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST
Some important points:
  • I need it to be restricted.
  • This field doesn't use a global value set.
  • There's no record types defined for this object.
  • The value I'm trying to set are in the value set, and I already checked for typos.
  • If I unmark the "Restrick picklist to values..." option, the record saves, but an identical value is added to the picklist. 
  • I use the API value for the assignation, but I've tried with Label too.
  • The user can set the value trhough User Interface correctly
What could be happening here? 
Regards,
Mario Bravo
dandamudidandamudi
@Mario
in case if it is restricted picklist then this error is possible only : 1) when the value itself is not included in the picklist or 2) when that picklist is not included in the record type. If you take care of these two, we will never get this error

Did you try with system.debug log after assigned the value in Apex code?
Sandeep YadavSandeep Yadav
Hello Bravo
Use insert statement in try catch block like this--
try{
   insert  record;
}
catch(Exception e)
Let me know if this helps you !!.