function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jimc507jimc507 

How to get the description of a sObject or field from Apex

is there a way to get the description from the describe functions is Apex. I have looked at the Schema.DescribeSObjectResult and Schema.DescribeFieldResult objects and did not see them. Is there another method or am I overlooking something?

 

Thanks in advance

Jim

Best Answer chosen by Admin (Salesforce Developers) 
Ispita_NavatarIspita_Navatar

Hi,

 

Did you try the following code :-

 

public class DescribeDataCategoryGroupSample {
   public static List<DescribeDataCategoryGroupResult> describeDataCategoryGroupSample(){
      List<DescribeDataCategoryGroupResult> describeCategoryResult;
      try {
         //Creating the list of sobjects to use for the describe 
    
         //call 
    
         List<String> objType = new List<String>();

         objType.add('KnowledgeArticleVersion');
         objType.add('Question');

         //Describe Call 
    
         describeCategoryResult = Schema.describeDataCategoryGroups(objType);
   
         //Using the results and retrieving the information 
    
         for(DescribeDataCategoryGroupResult singleResult : describeCategoryResult){
            //Getting the name of the category 
    
            singleResult.getName();

            //Getting the name of label 
    
            singleResult.getLabel();

            //Getting description 
    
           singleResult.getDescription(); 
            //Getting the sobject 
    
            singleResult.getSobject();
         }         
      } catch(Exception e){
      }
      
      return describeCategoryResult;
   }
}

check the  code:- String description = result.getDescription(); highlighted in red in the above code.

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

All Answers

Ispita_NavatarIspita_Navatar

Hi,

 

Did you try the following code :-

 

public class DescribeDataCategoryGroupSample {
   public static List<DescribeDataCategoryGroupResult> describeDataCategoryGroupSample(){
      List<DescribeDataCategoryGroupResult> describeCategoryResult;
      try {
         //Creating the list of sobjects to use for the describe 
    
         //call 
    
         List<String> objType = new List<String>();

         objType.add('KnowledgeArticleVersion');
         objType.add('Question');

         //Describe Call 
    
         describeCategoryResult = Schema.describeDataCategoryGroups(objType);
   
         //Using the results and retrieving the information 
    
         for(DescribeDataCategoryGroupResult singleResult : describeCategoryResult){
            //Getting the name of the category 
    
            singleResult.getName();

            //Getting the name of label 
    
            singleResult.getLabel();

            //Getting description 
    
           singleResult.getDescription(); 
            //Getting the sobject 
    
            singleResult.getSobject();
         }         
      } catch(Exception e){
      }
      
      return describeCategoryResult;
   }
}

check the  code:- String description = result.getDescription(); highlighted in red in the above code.

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

This was selected as the best answer
ConCocToConCocTo

For everayone else, please be aware that the provided solution does not work with custom fields for any custom object, but only with certain types that provide categories, e.g.

  • issues
  • ideas
  • articles
  • questions

See: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_describedatacategorygroups.htm#sforce_api_calls_describedatacategorygroups

Tristyn MaaloufTristyn Maalouf
This data is available for both custom and standard objects using the Tooling API. The following query should work:

Select Label, QualifiedApiName, Description from FieldDefinition Where EntityDefinition.QualifiedApiName='Account'

Just use the API name for whatever custom or standard object you'd like to see field descriptions on for EntityDefinition.QualifiedApiName and ensure you have 'Use Tooling API' selected in the developer console if that's where you're running this. To run this in Apex and access the results, see https://github.com/CompassionIntl/SalesforceSchemaAuditor/blob/master/classes/FieldAuditor.cls for an example of how this would work and other metadata you can gather on fields using the Tooling API.