Displaying default picklist value on Visualforce page using apex class controller
Here, we do not need to use SOQL and thus eliminates the Salesforce Governer limitations.

Check the default checkbox against the value which needs to be defaulted
Steps to make the default value in Lead Object field called Status
Setup -> Lead (Object) -> Click Status field -> check the default checkbox against the value from Status value lists.

I have chosen – “Open – Not Contacted”.

Apex Class:

public class defaultPicklistController {

public Lead lead {
public List < SelectOption > statusOptions {
// Constructor called on load.
public picklistController() {
lead = new Lead();
statusOptions = new List < SelectOption > ();

// Use DescribeFieldResult object.
Schema.DescribeFieldResult statusFieldDescription = Schema.Lead.Status.getDescribe();
// For each picklist value, a new select option created
for (Schema.Picklistentry picklistEntry: statusFieldDescription.getPicklistValues()) {
statusOptions.add(new SelectOption(pickListEntry.getValue(), pickListEntry.getLabel()));
// check default value and assign
if (picklistEntry.isDefaultValue()) {
lead.Status = picklistEntry.getValue();

Visualforce Page:

<apex:page controller="defaultPicklistController">
<apex:form >
<b>Default value of Lead Status : </b>
<apex:selectList size="1" value="{!lead.Status}">
<apex:selectOptions value="{!statusOptions}"/>



Written by 

3x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

Your email address will not be published.