As a Salesforce Admin or Developer, you’ve likely faced the challenge: you need to understand all the fields on a particular object. It seems straightforward, right? You go to Object Manager, click on “Fields & Relationships,” and there they are. But what about fields that aren’t immediately visible? What about fields you need to access programmatically?
The truth is, finding “all” fields can be a bit more nuanced than a quick glance. This post will be your definitive guide to unearthing every field on a Salesforce object, from the declarative UI to the power of the Metadata API and Apex.
Sample code:
Apex Class:
SObjectType objType = Schema.getGlobalDescribe().get( 'Account' );
Map < String, Schema.SObjectField > mapFields = objType.getDescribe().fields.getMap();
for (
String strField : mapFields.keySet()
) {
SObjectField field = mapFields.get( strField );
Schema.DescribeFieldResult fieldResult = field.getDescribe();
System.debug(
fieldResult.getLabel() + ' - ' +
fieldResult.getName()
);
}