Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

When you add an new field to an object in Salesforce.com, it is possible to check the "Required" checkbox to make it mandatory for every data insert/update. I know it is possible to make it required from a layout, but these conditions are not applied when inserting or updating the database from an Apex code.

Is there a reason why there's no way to do the same with a picklist field?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

I don't know if there is a reason why it is not possible, but no, it is not possible to set it required as part of the custom field.

If you absolutely must make it required, provide a default value and/or write a validation rule that verifies that a value is selected on insert and update. This should ensure that a value is always associated to that field.

Here is the validation rule you need:

ISPICKVAL(Test_Value__c,'')

where Test_Value__c is the API name of your field.

share|improve this answer
    
How do you plan to check something is filled in with a "workflow rule"... Is that a typo? –  eyescream Jan 24 '13 at 16:11
    
Yep, I meant validation rule. Thanks! –  Jesse Altman Jan 24 '13 at 16:14
    
Ok, then I'm deleting mine and giving you +1, I thought you're really answering in some harebrained workflow-y way. But ISBLANK works just fine on multiselect picklists ;) –  eyescream Jan 24 '13 at 16:15
    
Yes, this is what I am doing right now, using a validation rule. I really don't get it, this should be a built-in feature to preserve data integrity. I'll wait to see if somebody else has another answer to justify the reason behind this. –  jpmonette Jan 24 '13 at 16:45
    
I would assume it is related to fact that picklists have the --None-- value when no default option is selected and/or the fact that dependent picklists exit. This is just speculation as I have no idea how they store all of that data under the covers. Hopefully someone else has a good idea of why it isn't base functionality. –  Jesse Altman Jan 24 '13 at 16:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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