February 9, 2021

How to get all Data Categories using Apex in Salesforce?

Sample Code:

List < DescribeDataCategoryGroupResult >  describeCategoryResult = new List < DescribeDataCategoryGroupResult >();
List < String > objType = new List < String >() ;
objType.add ( 'KnowledgeArticleVersion' ) ;

//Describe Call
describeCategoryResult = Schema.describeDataCategoryGroups( objType ) ;
system.debug( 'All Categories '+ describeCategoryResult ) ;

//Using the results and retrieving the information
for ( DescribeDataCategoryGroupResult singleResult : describeCategoryResult )  {
    
    system.debug(
    singleResult.getName() + ' - ' +
    singleResult.getLabel() + ' - ' +
    singleResult.getDescription() + ' - ' +
    singleResult.getSobject());
    
}


No comments:

Post a Comment