Print this page

How to get the default value for a picklist in Apex

Knowledge Article Number 000205530
Description When we create a record using Apex, the default values of picklist fields will not be populated until DML operation have occurred for the record. It will be empty after being instantiated.
Resolution Use the sample code below to get the default value so you can show it/use it. 

String defaultVal;

Schema.DescribeFieldResult F = Account.SamplePicklist__c.getDescribe();
List <Schema.PicklistEntry> pickVals = F.getPicklistValues();        
for (Schema.PicklistEntry pv: pickVals) {
    if (pv.isDefaultValue()) {
        defaultVal = pv.getValue();

promote demote