0

I am trying to fetch Knowledge Articles based on Data Category through the below dynamic Soql query.

String dynamicQuery = 'SELECT Id, Title FROM Knowledge__kav ' +
                                        'WHERE PublishStatus = \'Online\' ' +
                                        'WITH DATA CATEGORY Topics__c AT ({0})';


List<Knowledge__kav> kavList = Database.query(String.format(dynamicQuery, DynamicTopics));

Wherein 'DynamicTopics' is a list of String having the data category name.

The problem i am facing here is, i get all the articles without distinguishing which data category it belongs to.

I cannot put this in for loop as it might hit the limit.

I want the article to be fetched along with their data category or something from which i can distinguishing it with the data category

Can you please help me with this?

  • This is a limitation of the platform. You're going to have to work within the limits. You shouldn't present a situation where this could be a problem. – sfdcfox Dec 28 '18 at 9:31
  • @sfdcfox that's what the problem statement is.. i am not able to find a solution. – Ritz Arlekar Dec 28 '18 at 10:18
1

You need to use ArticleType_DataCategorySelection object to retrieve ParentId (which is Article Id) and DataCategory Names.

Here is an example from my DE where ArticleType is Documentation_Kav

SELECT Id, ParentId, Parent.Title, DataCategoryGroupName, DataCategoryName 
FROM Documentation__DataCategorySelection
WHERE Parent.PublishStatus = 'Online'

By the way, DataCategoryName cannot be filtered in SOQL query, this is Salesforce Limitation

Like, we cannot execute this query

SELECT Id, ParentId, Parent.Title, DataCategoryGroupName, DataCategoryName 
FROM Documentation__DataCategorySelection
WHERE Parent.PublishStatus = 'Online'
AND DataCategoryName IN ('ABC', 'XYZ')

For more information, refer Article Type__DataCategorySelection

  • Hi Santanu,.. there are too many records in my knowledge_DatacategorySelection object. the reason i dint use this object because i would hit the limit as i will have to fetch all the knowledge articles without any filters. – Ritz Arlekar Dec 28 '18 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.