1

We are building the application that needs to support Salesforce Classic Knowledge and Lightning Knowledge. As you might know these two knowledge types are not compatible between each other. In Classic Knowledge we work with ArticleTypes but in Lightning Knowledge with RecordTypes.

Enabling Lightning Knowledge changes your Org's Data Model to use Record Types rather than Article Types. Orgs with multiple articles types require data migration to consolidate article types before enabling Lightning Knowledge. IMPORTANT: After you enable Lightning Knowledge, you can't disable it. Test in a Sandbox or Trial org before enabling in production. https://help.salesforce.com/articleView?id=knowledge_lightning_enable.htm&type=0

Therefore we need to implement two different implementation of the logic (search).

But how to identify what type of Knowledge is enabled in the organization via Apex code? I've checked all Apex Classes related to Apex and didn't find anything that can answer this question.

0

When Lightning Knowledge is enabled, the ArticleType field cannot be queried. You can use this to check if lightning is enabled.

First, loop through all of the objects looking for Knowledge objects (they have a key prefix like "ka1" where 1 is some number). Then do a database query selecting the ArticleType field. If lightning is enabled then it returns a Query Exception "No such column". You can rescue this and return true, indicating that Lightning is enabled.

I haven't found a more direct way unfortunately. Here's my method in Apex:

private static Boolean checkForLightningKnowledge() {
  for (Schema.SObjectType o : Schema.getGlobalDescribe().values()) {
    Schema.DescribeSObjectResult obj = o.getDescribe();
    if (obj.isDeprecatedAndHidden()) continue;

    if (obj.getKeyPrefix() != null && Pattern.matches('ka[0-9]',obj.getKeyPrefix())) {
      String objName = obj.getName();
        try {
                    List<sObject> sobjList = Database.query('SELECT Id, ArticleType FROM ' + objName);

        } catch (QueryException e) {
          if (e.getMessage().contains('No such column')) {
            return true;
          }

        }

    }
  }
  return false;
}

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.