I am trying to learn Schema class. I want to get all the field names of any object using Schema.DescribeSobjectResult . Please explain with example

2 Answers 2


You can use the below code snippet :

SObjectType acc = Schema.getGlobalDescribe().get('Account');
Map<String,Schema.SObjectField> allFields = acc.getDescribe().fields.getMap();

From this, you can get all the fields of Account object. you can use similar thing for other objects also. Let me know if this helps.

  • it is working. but when i try to get results of all objects it is giving an error. SObjectType acc = Schema.getGlobalDescribe().get('sObject');
    – sfdcuser45
    Commented Jun 16, 2015 at 11:49

You can query all sobjects by taking all sobjects in a list first, and passing that list in the Schema.describeSObjects function like this :

set<string> gl = Schema.getGlobalDescribe().keyset();
list<String> allObjects = new list<String>();
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(allObjects);
for(Schema.DescribeSobjectResult res : results) 
 map<String, Schema.SObjectField> allFields  = res.fields.getMap();

Let me know if this helps. Thanks

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .