+ Start a Discussion

How to get custom field description

Hi Salesforce gurus,

I am looking to extract the description of Custom fields of a/multiple object from the org.
basically i am trying to get a spreadsheet with the object name, field name and Description of the field.

I tried the below but have reached a dead end
>Getdescribe Apex calls - the Description is missing from the .getdescribe call
>Tried using the metadata API from this link :https://salesforce.stackexchange.com/questions/141251/query-name-help-text-description-of-custom-fields-in-a-custom-object  - but the api was not installed completely as it faced more than 30000 in apex code for 5-6 classes.
>querying the Field Definition object from workbench - again this object omits the Description field in the object
>inlineHelpText field is useless, as the field havent been used in the org like the description Text box of custom fields.

Any idea where the Description for a custom field is stored ,there has to be some metadata object or any other way to get the description.

Thanks in Advance.
rajat Maheshwari 6rajat Maheshwari 6

Hi Arpan, 

Below is sample code snippet, please let me know the results :)

Map<String,List<String>> allField = new Map<String,List<String>>();
      Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();    
        Map <String, Schema.SObjectField> fieldMap = gd.get('Account').getDescribe().fields.getMap();

        for(Schema.SObjectField fieldAPI : fieldMap.values())
          //    Schema.DescribeFieldResult dfield = fieldAPI.getDescribe();
            System.debug('Help Text' + fieldAPI.getDescribe().getInlineHelpText());

Rajat Maheshwari
Carolyn Campbell 29Carolyn Campbell 29

I have a workaround with SOQL query:

1) Identify the DurableID for the object(s) in the EntityDefinition table

 Select DeveloperName, DurableID from EntityDefinition

2) Query the FieldDefinition table (requires the EntityDefinition durable ID field):

SELECT entityDefinition.QualifiedAPIName /*objectname*/, Label, DeveloperName,  Description FROM FieldDefinition where entitydefinition.durableid in ('OpportunityStage' , 'LeadStatus' , 'CaseStatus' , 'Campaign' , 'CampaignMember' , 'Account' , 'Contact' , 'Lead' , 'Opportunity' , 'OpportunityContactRole' , 'Case' , /*custom objects will have 15-digit durableID */ '01I3k000002LRS2' , '01I3k000002LTw3' , '01I3k000002LTR0' , '01I3k000002LTR1')

You can then at least concatenate the Description field as a separate string into your output, with whatever else you need from the getDescribe() field results, as shown in Rajat's example above.  

The FieldDefinition table contains a few of the other items from GetDescribe(), if you would like to include them in your query, but getDescribe() handles them better, as well as pulls additional information from other tables in a handy way, so I like to use that.

For further edification:  
FieldDefinition API info:  https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_fielddefinition.htm
EntityDefinition:  https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_entitydefinition.htm

Note:  In all cases that I've tested this, all fields in these tables are read-only, and can only be updated through the Object Manager browser interface.