Play Games

Search This Blog

Monday, September 28, 2020

How to get all the values of a picklist field salesforce - Salesforce Globe For You

 How to get all the values of a picklist field salesforce  - Salesforce Globe For You 

Here in this example getting the leadSource (picklist) field values of Lead object.

Apex class:

public class PicklistValuesController {

    public List<String> lstLeadStatus {get;set;}

    public PageReference getLeadStatusValues() {

        lstLeadStatus = new List<String>();

        Schema.DescribeFieldResult fieldResult = Lead.LeadSource.getDescribe();

        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

        for (Schema.PicklistEntry a : ple ) {

          lstLeadStatus.add(a.getValue());

        }

        system.debug('List Of Values:'+lstLeadStatus);

        return null;

    }

}

Visualforce Page:LeadStatusValues

<apex:page controller="PicklistValuesController" action="{!getLeadStatusValues}">

<b>The Lead Status Values are:</b><br/>

<apex:repeat value="{!lstLeadStatus}" var="staus">

   {!staus}<br/>

</apex:repeat>

</apex:page>

Output:



No comments:

Post a Comment