1

Making a picklist field as required means to remove the --None-- option.

A picklist cannot be made required in the field setup.

In a standard detail page, a picklist can be made required by checking the Required checkbox in the page layout. This removes the --None-- option from the picklist options.

However, in a Visualforce page, an picklist cannot be made required with required="true", even if the picklist has a default value specified in setup.

How to make a picklist input field as required in a Visualforce page?

I do not want to resort to dirty Java Script code unless there is no other solution.

1

With the new Winter 17 release existing custom picklist fields can now be marked as required at a field level.

enter image description here

To create or modify custom picklists:

Picklist on an object — Use the fields area of the object.

Global picklist — From Setup, enter picklist in the Quick Find box, then select > Picklists.

Taken from the release notes for Winter 17.

4

Use Validation Rule to make it required.

ISBLANK(ShippingCountry) an example .

In visualforce you will need to catch error from validation in controller and use

 ApexPages.addmessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select a value'));
     return null;

Then use<apex:Pagemessages/> in Visualforce.

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.