I followed the article below and got the picklist label-name instead of API name for an object. How to query 'Value' of a picklist rather than the 'API NAME', using SOQL?

However while updating the object we get the error below. INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST

This is problematic, as now there is no way to get the API name of the field.

  • This is probably due to the new value is not match with the existing picklist values added. If you want to update the value either uncheck Restrict picklist to the values defined in the value set option in picklist field or add new value as picklist entry. – Reshma Jan 10 '19 at 9:12
  • If you query the API name, you can get the corresponding value by walking the describe information for the picklist. – David Reed Jan 10 '19 at 12:30

toLabel is only meant for presentation purposes. You should be querying the API name (the type that comes back by default) if you intend to do an update. You should use a describeSObject call to get the picklist API names and labels, instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.