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


I had 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 I achieved it:

Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get(‘Account’).getDescribe().fields.getMap();

for(String s : objectFields.keySet())
      // process s

About the author

Nishant Bamb
By Nishant Bamb