Using Apex with Knowledge
In continuation of my effort to make Lightning Knowledge easily understandable for all, today I am going to show how Salesforce Knowledge can be accessed using Apex. Salesforce Knowledge can have Apex Triggers and be accessible through Apex code. Actually, Salesforce provides some standard apex classes related to Knowledge Management that can be called for actions like publishing, editing as draft, archiving, and more.Before I start, I would recommend you going through my earlier posts -Understanding Salesforce Lightning Knowledge Data ModelHandy SOQL/SOSL Queries for KnowledgeWe can use the methods in KbManagement.PublishingService class to manage the lifecycle of an article. I am going to explain some of the few classes which developer needs mostly, but to know about all the methods, I highly recommend you going through the documentation here.Editing an Article as DraftWe can use the below method to edit an article as draft – String newId = KbManagement.PublishingService.editOnlineArticle( knowledgeArticleId, false );Where the 1st input parameter is the KnowledgeArticleId (Note – This is not the Knowledge Record Id).2nd parameter is a Boolean value where false will not unpublish the already published articles and true will unpublish the already published article.This method will return the new draft master version ID of the article.Note – We need to keep this in mind that this method is not bulkified. So if...
Read More