3

I am trying to fetch data category groups and categories, so that i can use it in my VF page. how do i query(SOQL) so that i can see all available data categories?

Datacategory

3

If you know the sObject to find categories for, you can access these using Dynamic Apex (describe calls). This is an example lifted from the Apex Developer Guide that lists all categories available for KnowledgeArticleVersion and Question objects.

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.