0

Currently, I'm just using this line: opp.LeadSource = 'Web'; as a static value to set the opp.LeadSource picklist on my vf page. Is there any way to do it dynamically? Instead of using static, I hope I can get whatever default value set on LeadSource, like: opp.LeadSource = (get any default value assigned to lead source). Any way how to do it?please...

0

Check this knowledge article "Get the default value for a picklist in Apex".

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();
    }    
}
|improve this answer|||||

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