3

I know there can be multiple data categories, but if I could pull them into a custom field, I could at least do a “contains” filter for the articles.

What formula in a custom field on the Knowledge object would pull in the data categories?

  • Check my answer, it will going to work for you – Santanu Boral Jul 16 '17 at 16:41
3

Try using KnowledgeArticleVersion instead of KnowledgeArticle. From the Object Reference:

Use this object to:

  • Query or search generically across multiple article types.
  • Filter on a specific version.
  • Update standard fields, those fields that are updateable, in draft versions.

When you query on the archived article, the results include both the article and the article’s archived versions.

Also, use KnowledgeArticleVersion with describeDataCategoryGroups() and describeDataCategoryGroupStructures() to return the category groups and the category structure associated with Salesforce Knowledge.

You can filter by PublishStatus='online' to get only the current version available.

  • it is tricky as trigger is not supported, check my answer – Santanu Boral Jul 16 '17 at 16:42
2

First of all, formula field will not going to work in this scenario.

Knowledge Article Version can have multiple DataCategories.Refer this data model. Salesforce Knowledge Objects

DM

Secondly, trigger is not supported on Article Types.

Solution

  • Create a Custom Field Data_Categories__c Text (255) in the Article Type (e.g. Help Document is Article Type)

  • Create an @invocable method like this which will retrieve data categories based on the Article Type Version and finally update those in the Custom field:

Code

public class ArticleAction {
    @InvocableMethod
    public static void updateArticleTypeForDataCategories(List<Id> articleTypeIds) 
    {
        List<Help_Document__kav> lstArticleType = [SELECT Id, Title, Data_Categories__c FROM Help_Document__kav WHERE Id IN:articleTypeIds 
                                                    AND PublishStatus = 'draft'];

        List<Help_Document__DataCategorySelection> lstDC = [SELECT ParentId, DataCategoryName   FROM Help_Document__DataCategorySelection
                                                            WHERE ParentId IN:articleTypeIds];

        Map<Id, String> datacategoryNameMap = new Map<Id, String>();

        for(Help_Document__DataCategorySelection dcObj:lstDC)
        {   
            if(datacategoryNameMap.containsKey(dcObj.ParentId))
            {
                String str =  datacategoryNameMap.get(dcObj.ParentId);
                datacategoryNameMap.put(dcObj.ParentId, str + ',' + dcObj.DataCategoryName);
            }
            else
            {
                datacategoryNameMap.put(dcObj.ParentId, dcObj.DataCategoryName);
            }
        }

        for(Help_Document__kav artObj:lstArticleType)
        {
            if(datacategoryNameMap.containsKey(artObj.Id))
            {
                artObj.Data_Categories__c = datacategoryNameMap.get(artObj.Id);
            }
        }

        update lstArticleType;
    }    
}
  • Call this invocable method from Process builder. You will see dataCategories will be saved in Comma delimited way.

Invocable from PB

  • For Archived articles, make those as draft and finally call this method from DeveloperConsole or other batch process.
  • is that my answer worked for u? did u check that? – Santanu Boral Jul 18 '17 at 4:25

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.