I'm trying to get all Data Categories from an Article Type through the varius describe calls I've found in the documentation such as https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Schema_DescribeDataCategoryGroupStructureResult.htm

This is the code I'm using, running it through Anonymous Apex

List <DataCategoryGroupSobjectTypePair> pairs = 
      new List<DataCategoryGroupSobjectTypePair>();

DataCategoryGroupSobjectTypePair pair1 = 
      new DataCategoryGroupSobjectTypePair();


List<Schema.DescribeDataCategoryGroupStructureResult>results = 
      Schema.describeDataCategoryGroupStructures(pairs, true);
          for(Schema.DescribeDataCategoryGroupStructureResult r : results){
              System.debug(r.getName()); //'MyArticles'
              Schema.DataCategory[] topCategories = r.getTopCategories();
              for(Schema.DataCategory c : topCategories){
                  System.debug(c.getName()); //'All'
                  Schema.DataCategory[] subCats = c.getChildCategories();
                  System.debug(subCats); //empty, why?
                  for(Schema.DataCategory sc: subCats){
                      System.debug(sc.getName()); //Never reached

My Data Categories are structured with one 'All' Category at the top level, which I can find using getTopCategories(), but when I call getChildCategories()on the result, I get an empty list, despite the fact that I have 5 child categories set up under it. I made sure Data Category Visibility is on, but I still get no results. Is there any other reason I wouldn't be able to see these subcategories?


It's because the ",true)" in the method call for describeDataCategoryGroupStructures stands for "topCategoriesOnly"


Turn this to false, and you should be good to go 🤙


I think this should work

<knowledge:categoryList categoryVar="category" categoryGroup="{!CategoryName}" rootCategory="All" level="1">
         <a href="/apex/vf_SubCategoryTopics?ptype={!CategoryName}&sctype={!category.Name}"> <apex:outputText value="{!category.Label}" /> </a>
        <br />

        <br />
     <!--    <apex:outputText escape="false" value="{!LPAD(' ',6*category.depth,'&nbsp;')}" /> -->


You can make the level="-1" to get unlimited category. for level ="1" it will just give you the sub category. The tag works like loop and gets what you need! Worked for me while working for a knowledge base: Please mark my answer accepted if it works !

If you need any other help refer to this guide This links is all about the knowledge base development

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.