Fetch picklist value of standard or custom picklist field
In this blog, we will learn how to fetch picklist value of standard or custom picklist field through apex class. Let’s get started.
Fetch picklist value of standard or custom picklist field
Let’s start with controller code.
public with sharing class retrieveStageValue { /** * Webkul Software. * * @category Webkul * @author Webkul * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https://webkul.com) * @license https://store.webkul.com/license.html */ public list getoppst(){ //Create a list of select option type list<selectoption> opt = new list<selectoption>(); //FieldDescription=SObjectName.FieldName.getDescribe() schema.DescribeFieldResult fd = opportunity.stagename.getdescribe(); //Get all picklist value in a list of scheme.picklistentry type list<scheme.picklistentry> pc = fd.getpicklistvalues(); //Add each value in the list of selectoption for(schema.picklistentry f: pc){ opt.add(new selectoption(f.getlabel(),f.getvalue())); } return opt; } }
Now the visualforce page code:
<apex:page controller="retrieveStageValue"> <!-- /** * Webkul Software. * * @category Webkul * @author Webkul * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https://webkul.com) * @license https://store.webkul.com/license.html */ --> <apex:form > <apex:sectionHeader title="Opportunity" subtitle="Status Picklist Value"/> <apex:pageblock > <apex:pageblocksection > <apex:pageblocksectionitem > <apex:outputlabel value="Opportunity Stage"/> <apex:selectlist size="1"> <apex:selectoptions value="{!oppst}" /> </apex:selectlist> </apex:pageblocksectionitem> </apex:pageblocksection> </apex:pageblock> </apex:form> </apex:page>
Support
That’s all about how to fetch picklist value of standard or custom picklist field, for any further queries feel free to contact us at:
https://wedgecommerce.com/contact-us/
Or let us know your views on how to make this code better, in comments section below.