Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

Is it possible to get a list of all API Names for all fields on an object?

Schema.DescribeSObjectResult r =Object__c.sObjectType.getDescribe();
List<String>apiNames =  new list<String>();
for(Schema.DescribeSObjectResult result : r){
   apiNames.add();   //this is where I am lost. 
}

1 Answer

0 votes
by (32.1k points)
edited by

You can use the fields method to get the Schema.SObjectTypeFields.

Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();

List<String>apiNames =  new list<String>();

for(string apiName : r.fields.getMap().keySet()){

   apiNames.add(apiName);

}

System.debug(apiNames);

I will recommend you this salesforce certification course from Intellipaat. This training provides all the required skills and helps you to become a certified salesforce developer! 

Browse Categories

...