You need to sign in to do that
Don't have an account?
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
Thanks for replying Naishadh. 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
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); }
Thanks for replying Naishadh. 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