I have ~1000 Knowledge Articles that need to be updated. I've come across this class to accomplish this programmatically. Although I'm getting the following error every time I try to call one of these methods.

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.

This is the code that generated the error:

for(Article_Type__kav k : [SELECT Id, ArticleNumber, KnowledgeArticleId 
                             FROM Article_Type__kav 
                            WHERE PublishStatus = 'Online' 
                              AND Language = 'en_US']){
String onlineK=KBManagement.PublishingService.editOnlineArticle(k.KnowledgeArticleId,false);

I've tried the same using the KnowledgeArticleVersion and filtering by type as well. Same error. I'm running this as a system administrator and am able to create/edit/update/delete/publish articles through the UI as well. Is there a permission I'm missing to utilize the PublishingService class? Any help is greatly appreciated.


This method creates draft articles from online articles, so this happens because one or more of those online article already has a draft article so you cannot create another draft article(you cannot have 2 drafts for a single article at the same time).

This should work for you

    for(FAQ__kav k : [SELECT Id, ArticleNumber, KnowledgeArticleId
                      FROM FAQ__kav
                      WHERE PublishStatus = 'Online'  AND Language = 'en_US']){
             String onlineK=KBManagement.PublishingService.editOnlineArticle(k.KnowledgeArticleId,false);
     catch(exception e){
         //nothing to do here, draft existed 

  • He is querying only online articles . – Mohith Shrivastava Mar 25 '16 at 17:25
  • Let us continue this discussion in chat. – Mohith Shrivastava Mar 25 '16 at 17:26
  • @PepeFloyd I suspect you are correct as I tested this in a Sandbox org where there were already draft versions of some of the articles I was trying to edit. I ended up wrapping the method call in a try/catch and was able to see the cause. Thanks for your help. – Antonio Manente Mar 25 '16 at 17:36
  • I just upvoted this answer .Strange that query dont filter out draft articles . – Mohith Shrivastava Mar 25 '16 at 17:38

The issue may be caused due to

1.You dont have knolwedge User Checked on your user .From your description of problem I am ruling this out since you say from UI you are able to do this .But just double check your user record to see if knowledge User is checked

2.Ensure proper permissions like

“Manage Articles” (This permission is on by default in the System Administrator profile.)


“Read”, “Create”, and “Edit” on the article type


A publish or archive article action, set on the Article Actions Setup page

Also note that if one of records fail in your code ,all the records fail ,try doing with hardcoded Id first one by one

KBManagement.PublishingService.editOnlineArticle('put your harcode Id once',false); 
  • Hey, thanks for your response. I verified that some of the records failed in the code, causing it to throw the exception. – Antonio Manente Mar 25 '16 at 17:34
  • Use those Ids now to figure why they error out .May be those are locked for you to not edit .Also check below answer from Pepeflyod .Are those draft articles ? Please share your further findings – Mohith Shrivastava Mar 25 '16 at 17:36
  • I commented on Pepefloyd's answer. He was correct. I tested this in a Sandbox org where there were already draft versions of some of the articles I was trying to edit. That was the cause of the exception. – Antonio Manente Mar 25 '16 at 17:38
  • 1
    Great !!Its weird that your query dont filter draft articles .I think now you need to check for all article versions and query only those that have no draft article version in them ... – Mohith Shrivastava Mar 25 '16 at 17:40

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.