Pages

Tuesday, June 30, 2026

Salesforce: SOQL Knowledge

Before we start, let us put a few notes related to Salesforce knowledge:

  • You can create a multi-level category: parent, child, grandchild, etc.
  • You can assign multiple categories in an article, including ones that are not from the same hierarchy
  • You can assign the article to the parent only (not including the child)

There are 2 special keywords to query the knowledge object, but you can't get the data category in the query result. 

  1. WITH DATA CATEGORY
  2. AT, BELOW, ABOVE, ABOVE_OR_BELOW

Sample: SELECT Id, Title FROM Knowledge__kav WITH DATA CATEGORY Product__c AT Laptop__c

You must use the API Name in the query such as: All_Product__c, not the label: All Product

1. AT (Exact match only)


2. BELOW (Category + all children)


3. ABOVE (Category + all parents)


4. ABOVE_OR_BELOW (Everything around it)


Tips:

You can use the AND logical operator, but not the OR logical operator. Example: you have article with two Category Groups, sample: SELECT Id, Title FROM Knowledge__kav where PublishStatus = 'Online' WITH DATA CATEGORY Region__c AT Singapore__c AND Product__c AT Mobile__c

To query with more than one Category Name, use parentheses and a comma, sample: SELECT Id, Title FROM Knowledge__kav where PublishStatus = 'Online' WITH DATA CATEGORY Region__c AT (Singapore__c, Malaysia__c)


Reference



No comments:

Post a Comment

Page-level ad