You need to sign in to do that
Don't have an account?
Kasia Wojewodzka 7
Cannot move Published article to draft via apex. Error
Hi I am trying to mass update Knowledge Articles from Published to Drafts (Developer Console: Debug> Execute Anonymos Windwow)
Its been working succesfully with smaller updates until when I got about 1600 articles to update.
I am getting the follwoing 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.
I think we may be running into "one or more of those online article already has a draft article" issue mentioned here: https://salesforce.stackexchange.com/questions/115592/mass-updating-published-articles
I am new to apex code. Would you advise how to modify the exsiting code i have to use Try and Catch ? Thank you in advance for your help.
Kasia
Its been working succesfully with smaller updates until when I got about 1600 articles to update.
List<Knowledge__kav> articleIds = [SELECT Id,Region__c,LastPublishedDate,Line_of_business__c,Title, KnowledgeArticleId FROM Knowledge__kav WHERE PublishStatus = 'Online' AND Title <> 'Digital Cytology: Slide Scanning' AND Title <> 'SNAP Tests: Universal SNAP Protocol Checklist' AND Title <> 'SNAPShot Dx: Streaking and/or Speckling' AND Title <> 'This is a test of LOB and Region' AND Title <> 'SNAPShot Dx: Streaking and/or Speckling' AND Title <> 'Cornerstone: Lab results run under the wrong patient - wrong patient on lab report PDF' AND Line_of_business__c ='' AND Language = 'en_US' WITH DATA CATEGORY Line_of_Business__c AT (IHD__c) LIMIT 100]; for(Knowledge__kav article : articleIds){ KBManagement.PublishingService.editOnlineArticle(article.KnowledgeArticleId, true); } system.Debug(articleIds.size());
I am getting the follwoing 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.
I think we may be running into "one or more of those online article already has a draft article" issue mentioned here: https://salesforce.stackexchange.com/questions/115592/mass-updating-published-articles
I am new to apex code. Would you advise how to modify the exsiting code i have to use Try and Catch ? Thank you in advance for your help.
Kasia
This error 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).
You can modify your existing code like below to avoid the error and catch it in your apex code:
Since, you are new to Apex code, I would recommend you learning the usage of Try Catch to handle the exceptions.
Reference:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_trycatch_example.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_statements.htm
Hope above information helps, Please mark as Best Answer so that it can help others in the future.
Thanks.
All Answers
This error 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).
You can modify your existing code like below to avoid the error and catch it in your apex code:
Since, you are new to Apex code, I would recommend you learning the usage of Try Catch to handle the exceptions.
Reference:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_trycatch_example.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_exception_statements.htm
Hope above information helps, Please mark as Best Answer so that it can help others in the future.
Thanks.