获取对象的所有字段的API名称的列表。

Tho*_*ler 3 schema salesforce apex-code

是否可以获取对象上所有字段的所有API名称的列表?

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. 
}
Run Code Online (Sandbox Code Playgroud)

Dan*_*ger 5

您可以使用fields方法获取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);
Run Code Online (Sandbox Code Playgroud)