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
Anmol Verma 34Anmol Verma 34 

How to get a list of knowledge article linked to some data category in soql apex

I have a requirement where in i need to fetch a list of knowledge articles related to a specific data category. Like my data category name is 'How_to__c' here I need to find the number of Knowledge articles linked to this data category.

Any help will be really appreciated
Best Answer chosen by Anmol Verma 34
SarvaniSarvani
Hi Anmol,

Please use below query. Replace your subcategory name at "Subcategory__c" . This gives the count of articles related to SubCategory under How_to__c. 
SELECT count() FROM KnowledgeArticleVersion WHERE PublishStatus='online' with data category How_to__c At SubCategory__c
If you have multiple categories under How_to__c and want to query all articles under it use WITH DATA CATEGORY How_to__c AT (Sub1__c,Sub2__c,Sub3__c)

Please refer to the links:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_with_datacategory_examples.htm
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_with_datacategory_catselection.htm

Hope this helps! Please mark as best if it answers.

Thanks

All Answers

SarvaniSarvani
Hi Anmol,

Please use below query. Replace your subcategory name at "Subcategory__c" . This gives the count of articles related to SubCategory under How_to__c. 
SELECT count() FROM KnowledgeArticleVersion WHERE PublishStatus='online' with data category How_to__c At SubCategory__c
If you have multiple categories under How_to__c and want to query all articles under it use WITH DATA CATEGORY How_to__c AT (Sub1__c,Sub2__c,Sub3__c)

Please refer to the links:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_with_datacategory_examples.htm
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_with_datacategory_catselection.htm

Hope this helps! Please mark as best if it answers.

Thanks
This was selected as the best answer
Ema walkerEma walker
Please use below query. Replace your subcategory name at "Subcategory__c" . This offers the best capsules (https://topbestnespresso.com/best-nespresso-capsules/)the remember of articles associated with SubCategory beneath How_to__c. For 
Anmol Verma 34Anmol Verma 34
Hi Sarvani,

Thanks for you reply. Your solution works fine for my use case. Thanks for the solution.
Marking your solution as 'Best Answer'.

Cheers!

Anmol