1

I am trying to implement a requirement where few knowledge articles based on the priority(custom picklist) will be auto published immediately they are getting created.

I am currently doing this with workflow and knowledge action. Tried using the KbManagement.PublishingService.publishArticle as well in the Trigger, but is this only available for Classic Knowledge and not for Lightning Knowledge?

Also apart from what I am doing, is there any better approach to solve this problem?

2 Answers 2

4

KbManagement.PublishingService.publishArticle is supported for both classic as well as lightning.

You need to pass the Knowledge__kav.KnowledgeArticleId field to it and not Knowledge__kav.Id.

Sample code

public class TriggerHandlerOnKnowledge {
    public static void run() {
        if(Trigger.isAfter && Trigger.isInsert) {
            publishHighPriority((List<Knowledge__kav>)Trigger.new);            
        }
    }

    private static void publishHighPriority(List<Knowledge__kav> articles) {
        for(Knowledge__kav article: articles) {
            if(article.priority__c == 'High') {
                KbManagement.PublishingService.publishArticle(article.KnowledgeArticleId, false);
            }
        }
    }
}
3
  • Yes that's what I was doing. My problem here is that seems like this api is not bulkified. I am not sure what's the impact on Salesforce limit's like DML and all. Commented Mar 16, 2020 at 13:45
  • 1
    Yes, that's a downside, however, considering real scenario knowledge articles are mostly created by authors one at a time. To be safe you can add an additional check on the size of Trigger.new and delegate the job to a batch class in case of bulk upload. Commented Mar 16, 2020 at 14:56
  • Makes sense. Thanks Anmol Commented Mar 16, 2020 at 16:44
-1

you can use knowledge actions (Workflow field updates) to publish a new version

1
  • OP says he is already using workflow and knowledge action. Commented Jul 12, 2020 at 21:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .