dataCategorySelection

The syntax of the data category selection in a WITH DATA CATEGORY clause in a SOQL query includes a category group name to use as a filter, the filter selector, and the name of the category to use for filtering.

The dataCategorySelection uses the following syntax:

SyntaxDescription
dataCategoryGroupNameThe name of the data category group to use as a filter. Geography__c is the data category group in the following example. You cannot use the same data category group more than once in a query. For example, the following command is incorrect: WITH DATA CATEGORY Geography__c ABOVE usa__c AND Geography__c BELOW europe__c
filteringSelectorThe selector used to filter the data in the specified data category. See Filtering Selectors for a list of valid selectors.
dataCategoryNameThe name of the data category for filtering. You must have visibility on the category you specify. You can use parentheses to apply the filtering operator to more than one data category; each data category must be separated by a comma. For example: WITH DATA CATEGORY Geography__c AT (usa__c,france__c,uk__c). You can’t use the AND operator instead of parentheses to list multiple data categories. The following syntax does not work: WITH DATA CATEGORY Geography__c AT usa__c AND france__c

When specifying filters for a WITH DATA CATEGORY clause of a SOQL query, you can use AT to select the specified category, ABOVE to select the category and all its parent categories, BELOW to select the category and all its subcategories, and ABOVE_OR_BELOW to select the category, its parent categories, and its subcategories.

The examples in this section are based on the following data category group:

This table lists the filteringSelector values that are used in the dataCategorySelection syntax.

SelectorDescription
ATSelect the specified data category.
ABOVESelect the specified data category and all its parent categories.
BELOWSelect the specified data category and all its subcategories.
ABOVE_OR_BELOWSelect the specified data category, all its parent categories, and all its subcategories.

Example for AT — selects asia__c:

Example for ABOVE — selects usa__c, northAmerica__c, and ww__c:

Example for BELOW — selects northAmerica__c, usa__c, canada__c, and mexico__c:

Example for ABOVE_OR_BELOW — selects ww__c, europe__c, france__c, and uk__c:

Here are some more examples of WITH DATA CATEGORY clauses in a SELECT statement in a SOQL query.

Type of SearchExamples
Select the title from all questions classified with the mobile_phones__c data category in the Product__c data category groupSELECT Title FROM Question WHERE LastReplyDate < 2005-10-08T01:02:03Z WITH DATA CATEGORY Product__c AT mobile_phones__c
Select the title and summary from all published Knowledge articles classified above or below europe__c in the Geography__c data category group and below allProducts__c in the Product__c data category groupSELECT Title, Summary FROM KnowledgeArticleVersion WHERE PublishStatus='Online' AND Language = 'en_US' WITH DATA CATEGORY Geography__c ABOVE_OR_BELOW europe__c AND Product__c BELOW All__c
Select the ID and title from draft articles of type “Offer__kav” classified with the france__corusa__cdata category in theGeography__cdata category group and above thedsl__cdata category in theProduct__ data category groupSELECT Id, Title FROM Offer__kav WHERE PublishStatus='Draft' AND Language = 'en_US' WITH DATA CATEGORY Geography__c AT (france__c,usa__c) AND Product__c ABOVE dsl__c