How to get all field names in all objects using Apex in Salesforce?

How to get all field names in all objects using Apex in Salesforce?

Sample Code:

List < Schema.SObjectType > gd = Schema.getGlobalDescribe().Values();      
Map<String , Schema.SObjectType > globalDescription = Schema.getGlobalDescribe();   
        
for ( Schema.SObjectType f : gd ) {  
  
    Schema.sObjectType objType = globalDescription.get(f.getDescribe().getName() );  
    Schema.DescribeSObjectResult r1 = objType.getDescribe();   
    Map<String , Schema.SObjectField > mapFieldList = r1.fields.getMap();    
  
    for ( Schema.SObjectField field : mapFieldList.values() ) {    
      
        Schema.DescribeFieldResult fieldResult = field.getDescribe();    
  
        if ( fieldResult.isAccessible() ) {    
          
            System.debug(‘Field Name is ‘ + objType + ‘.’ + fieldResult.getName() );  
              
        }   
          
    }  
      
}  

Leave a Reply