Thursday, June 28, 2012

Using Schema.getGlobalDescribe() to get list of all fields in Apex


        For Example, We have one dropdown that had options – Lead, Account, Contact, Opportunities and some custom objects. Upon selection of any of this object, all the respective object’s standard and custom fields should be populated in another dropdown. 
This is how we can do it:
Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get(‘Account’).getDescribe().fields.getMap();
for(String s : objectFields.keySet())
{
      // process s
}

1 comment: