function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vasu takasivasu takasi 

how to Retrive the picklist values from the picklist field dynamically using if condition

hi i have two fields in my contact object like leadsource and level.

i want to get these values using if condition like

string s='level';

 if(type==s)
            {
                Schema.DescribeFieldResult pickval  =Schema.sObjectType.contact.fields.(:s).getSObjectField().getDescribe();
            }
i have to mension field name dynamically.

please help me.         

Best Answer chosen by Admin (Salesforce Developers) 
ibtesamibtesam

Hi,

 

if(type==s)
            {

 

 

Schema.DescribeFieldResult pickval =

 

Schema.getGlobalDescribe().get('contact').getDescribe().fields.getMap().get(s).getDescribe();

 

            }

 

Hope this helps.