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
MukulMukul 

Picklist values from getDescribe dynamically?

Hello all,

 

I am trying to achieve this:

 

I have a param thats passed through URL. The param is essentially a lead's field name which is picklist e.g.  Industry and so on.

 

I want to get these picklist values in a list.

 

Here is how am i doing it:-

 

String lookup = ApexPages.currentPage().getParameters().get('lookup'); Schema.DescribeFieldResult F; sObject s = new Lead(); // Get the sObject describe result for the Account object Schema.DescribeSObjectResult r = Lead.sObjectType.getDescribe(); // TODO: Get it dynamically if (lookup == 'Industry') { F = Lead.Industry.getDescribe(); } if (lookup == 'leadsource') { F = Lead.leadsource.getDescribe(); } if (lookup == 'Productinterest__c') { F = Lead.Productinterest__c.getDescribe(); } if (lookup == 'status') { F = Lead.status.getDescribe(); } if (lookup == 'Salutation') { F = Lead.Salutation.getDescribe(); } if (lookup == 'rating') { F = Lead.rating.getDescribe(); }

 

 

 

 However i dont want to hardcode the lookup value in If statements. Is there any way i can do a getDescribe dynamically on the leads field?

 

like - Lead.getFieldName(Lookup).getDescribe() ?

 

Thanks much!

Regards

Mukul 

Best Answer chosen by Admin (Salesforce Developers) 
MukulMukul

Thanks for replying . But i fixed it long time back. :-)

 

And this is what i did. I got the field names in the Map and compared the value by the get property.

 

Regards

Mukul

All Answers

NaishadhNaishadh

Try this!

 

Map<String, Schema.SObjectField> M = Lead.sObjectType.getDescribe().fields.getMap(); String lookup = ApexPages.currentPage().getParameters().get('lookup'); if(M.get(lookup).getDescribe().getType() == DisplayType.PICKLIST) { List<Schema.PicklistEntry> P = M.get(lookup).getDescribe().getPicklistValues(); System.debug(P); }

 

MukulMukul

Thanks for replying . But i fixed it long time back. :-)

 

And this is what i did. I got the field names in the Map and compared the value by the get property.

 

Regards

Mukul

This was selected as the best answer