WITH DATA CATEGORY is an optional clause that can be added to a SOSL query to filter all search results that are associated with one or more data categories and are visible to users. This clause is used in searches of Salesforce Knowledge articles and questions.
The WITH DATA CATEGORY clause can be used in API version 18.0 or later.
Syntax
The WITH DATA CATEGORY syntax is:
1WITH DATA CATEGORY DataCategorySpec [logicalOperator DataCategorySpec2 ... ]
Where DataCategorySpec consists of a groupName, Operator, and category.
Name
Description
groupName
The name of the data category group to filter. For information on category groups, see “Create and Modify Category Groups” in the Salesforce Help.
Operator
Use one of the following operators: AT—Queries the specified data category; ABOVE—Queries the specified data category and all of its parent categories; BELOW—Queries the specified data category and all of its subcategories; or ABOVE_OR_BELOW—Queries the specified data category, all of its parent categories, and all of its subcategories.
category
The name of the category to filter. To include multiple data categories, enclose them in parentheses, separated by commas. For information on categories, see “Add Data Categories to Category Groups” in the Salesforce Help.
You can add multiple data category specifiers by using the logical operator AND. Other operators, such as OR and AND NOT, are not supported.
A SOSL statement using the WITH DATA CATEGORY clause must also include a RETURNING ObjectTypeName clause, with a WHERE clause that filters on the PublishStatus field.
In the RETURNING clause, specify one of the following for ObjectTypeName:
To search a specific article type, use the article type name with the suffix __kav
For information on article types, see “Knowledge Article Types” in the Salesforce Help.
The WHERE clause must use one of the following publish statuses:
WHERE PublishStatus='online' for published articles
WHERE PublishStatus='archived' for archived articles
WHERE PublishStatus='draft' for draft articles
Examples
Search Type
Example
Search all published (online)Salesforce Knowledge articles with a category from one category group.
Example
Search online FAQ articles with categories from two category groups.
Example
Search archived FAQ articles from one category group.
Example
Search all draft Salesforce Knowledge articles from one category group.
Example
Search all published (online) Salesforce Knowledge articles with a category from one category group:
1FIND {tourism} RETURNING KnowledgeArticleVersion2 (Id, Title WHERE PublishStatus='online')3 WITH DATA CATEGORY Location__c AT America__c
Search online FAQ articles with categories from two category groups:
1FIND {tourism} RETURNING FAQ__kav2 (Id, Title WHERE PublishStatus='online')3 WITH DATA CATEGORY Geography__c ABOVE France__c4 AND Product__c AT mobile_phones__c
Search archived FAQ articles from one category group:
1FIND {tourism} RETURNING FAQ__kav2 (Id, Title WHERE PublishStatus='archived')3 WITH DATA CATEGORY Geography__c AT Iceland__c
Search all draft Salesforce Knowledge articles from one category group:
1FIND {tourism} RETURNING KnowledgeArticleVersion2 (Id, Title WHERE PublishStatus='draft')3 WITH DATA CATEGORY Geography__c BELOW Europe__c