How to find all custom fields in an Salesforce Object?

How to find all custom fields in an Salesforce Object?

isCustom() method from Schema.DescribeFieldResult can be used to find whether the field custom or standard in Salesforce using Apex.

Sample Apex Code:

Schema.DescribeSObjectResult objectDescribeResult = 
    Account.sObjectType.getDescribe();  
Map < String , Schema.SObjectField > mapFieldList = 
    objectDescribeResult.fields.getMap();    

for ( 
    Schema.SObjectField field : 
    mapFieldList.values() 
) {    
  
    Schema.DescribeFieldResult fieldResult = 
        field.getDescribe(); 

    if ( fieldResult.isCustom() ) {

        System.debug(
            'Field Label is ' + 
            fieldResult.getLabel()
        );
        System.debug(
            'Field Name is ' + 
            fieldResult.getName()
        );

    }
      
}

Output:

Leave a Reply