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)

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);
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.5k questions

29.9k answers

500 comments

99.1k users

Browse Categories

...