function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hiteshwar marnihiteshwar marni 

archive

list<KnowledgeArticleVersion> hrlist = new list<KnowledgeArticleVersion>();
String articleId = '';
hrlist=[SELECT ArticleType,Id,KnowledgeArticleId,Language,PublishStatus FROM KnowledgeArticleVersion WHERE ArticleType = 'How_To_HR__kav' AND Language = 'en_US' AND PublishStatus = 'Online'limit 100];

for(KnowledgeArticleVersion hr:hrlist)
{
    articleId = hr.KnowledgeArticleId;
    KbManagement.PublishingService.archiveOnlineArticle(articleId, null); 
    articleId = '';
}


I'm writing above code to mass Archive articles.Bu its throwing 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.
 
Damon ShawDamon Shaw
Hi hiteshwar,

your code worked for me, can you archive articles manually?

also, your your code could be shortened a little, try this
for(KnowledgeArticleVersion hr :[SELECT Id, KnowledgeArticleId FROM KnowledgeArticleVersion WHERE ArticleType = 'How_To_HR__kav' AND Language = 'en_US' AND PublishStatus = 'Online' limit 100])
{
    KbManagement.PublishingService.archiveOnlineArticle(hr.KnowledgeArticleId, null);
}