3

I can query articles with specific data categories, for example:

SELECT Title FROM KnowledgeArticleVersion WHERE PublishStatus='online' WITH DATA CATEGORY Geography__c ABOVE usa__c

But what if I want only the articles that do not have a value set for the Geography category?. There doesn't seem to be a simple way to negate this query.

3
  • Can you post the error you're getting?
    – Eric Clay
    Commented Feb 27, 2015 at 15:21
  • There is no error, the question is around how to do the opposite on that query. For example using WITHOUT doesn't compile because I guess it doesn't exist.
    – PepeFloyd
    Commented Feb 27, 2015 at 16:03
  • 1
    I thought I had it with this "SELECT Title FROM KnowledgeArticleVersion WHERE PublishStatus='online' AND Language = 'en_US' WITH DATA CATEGORY Product__c ABOVE All__c" but it includes the 'All' category. If your process is such that you never use that value it might be of interest.
    – Eric Clay
    Commented Feb 27, 2015 at 18:21

1 Answer 1

6

I know this is an old question, but I ran into the same problem today, and solved it like this:

Select Id, ArticleNumber, Title from ArticleType__kav where Id not in (Select ParentId from ArticleType__DataCategorySelection) and PublishStatus = 'Online'

You should replace ArticleType__kav and ArticleType__DataCategorySelection based on the name of your Article Type.

For example, if you have an Article Type called "Answer", the query would look like this:

Select Id, ArticleNumber, Title from Answer__kav where Id not in (Select ParentId from Answer__DataCategorySelection) and PublishStatus = 'Online'

What it does is looks for articles where there is no record in the DataCategorySelection object for that article type. Only articles with a Data Category assigned will have a record in that object.

3
  • Is there a way to do this that is not category specific?
    – jbyrd
    Commented Sep 27, 2022 at 18:00
  • @sfdcfox - any input on this? This seems to be an expensive query (especially when it's being run on key press), plus it only works on category-specific queries.
    – jbyrd
    Commented Oct 3, 2022 at 15:27
  • Thanks for the answer above it helped me! The below SOQL worked for me in 2024 (SF Summer 24 Release): Select Id, ArticleNumber, Title from Knowledge__kav where Id not in (Select ParentId from Knowledge__DataCategorySelection) and PublishStatus = 'Online' Commented Aug 15 at 9:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .