Update Knowledge Articles in Bulk

Recently we had a big Knowledge Centric Support (KCS) initiative where we generated a ton of Articles for use in a Community. (We're still on Classic Knowledge.)

Problem is, some users forgot to tick the "Customer" box when creating the Articles. So those articles didn't appear to external users in the Community.

You can update these Articles in bulk, but you need to use a few obscure hooks in Apex. This method will create a draft of the Article, update the Knowledge Article Version, and then re-publish without creating a new Version.

The following code will update the 'IsVisibleInCsp' flag for a single Article specified in the 1st query, which will make it visible to Customers.

Here's a bulkified version. This is heavy on the CPU so I run it 10 at a time.

When going over these in bulk, you might run into a situation where there is an existing draft of an article that has been previously published; i.e., it's actively being updated. In this example, we search for those situations and don't create revisions of them.

This will go over all articles of type BA_Public_Knowledgebase__kav, 10 at a time. Update the code for your KnowledgeArticleVersion name, then run in Execute Anonymous. When you're done it will report that it updated 0 articles.


  1. This is awesome. It helped me do the same for one of our requirements. I am facing one challenge though and unable to figure it out. It worked seamlessly for one article type but not working for any other article types. I am a system admin user and have all access to publish articles. Not sure what is the reason. Keep getting the below error:

    System.HandledException: You can't perform this action. Be sure the action is valid for the current state of the article, and that you have permission to perform it.

  2. Excellent article and with lots of information. I really learned a lot here. Do share more like this.
    Salesforce Training in Chennai
    Salesforce Training Online
    Salesforce Online course


Post a Comment

Popular posts from this blog

"Disjunctions not supported" - Why Custom Metadata and Flow Don't Mix

What Happens To "Inflight" Process Builders When You Activate a new Version?