2

I am trying to mass archive articles but entering the below in the developer console returns: Method does not exist or incorrect signature KbManagement.PublishingService.archiveOnlineArticle(LIST,NULL).

My guess is that this method doesn't accept a LIST only a single Id, in that case how can I mass archive those articles?

List<Documentation__kav> toDelete=new List<Documentation__kav>([Select Id, KnowledgeArticleId
     FROM Documentation__kav WHERE ImportId__c='' AND Language='en_US' AND PublishStatus='Online']);

List<Id> archiveArticles=new List<Id>();

for (Documentation__kav kav:toDelete)
{
    archiveArticles.add(kav.KnowledgeArticleId);

}

List<KnowledgeArticle> archived=new List <KnowledgeArticle>([Select Id from KnowledgeArticle WHERE ID=:archiveArticles]);

KbManagement.PublishingService.archiveOnlineArticle(archived,null)

Thanks

3 Answers 3

2

Try performing the archive in a batch.

Disclaimer: I put this together directly here to outline the idea. It may not compile or run as expected.

global class ArchiveArticles implements Database.Batchable<SObject> {
    global string query;

    global ArchiveArticles() {
        query = 'Select Id, KnowledgeArticleId FROM Documentation__kav WHERE ImportId__c=\'\' AND Language=\'en_US\' AND PublishStatus=\'Online\'';
    }

    global Database.QueryLocator start(Database.BatchableContext BC){
         return Database.getQueryLocator(Query);
    }

    global void execute(Database.BatchableContext BC, List<sObject> toDelete) {
        for (Documentation__kav kav:toDelete)
        {
            KbManagement.PublishingService.archiveOnlineArticle(kav.knowledgeArticleId,null);
        }    
    }

} 

When starting adjust the batch size to stay within the governor limits.

// Adjust this batch size as required.
integer batchSize = 25;
ID batchprocessid = Database.executeBatch(new ArchiveArticles(), batchSize);
2
  • I am accepting this as a solution as it compiled and seems like a good option, unfortunately it returned an internal server error when executed, probably a bug.
    – PepeFloyd
    Mar 18, 2013 at 0:24
  • @Daniel Can you please help with the question here salesforce.stackexchange.com/questions/309951/… where I am updating the knowledge article through data loader but gettting Only draft articles can be update : Publication Status error
    – user81642
    Jun 18, 2020 at 15:21
1

I think KbManagement.PublishingService class does not allow us to operate in bulk. It accepts a single Id. Moreover if you keep this operation in a for loop like :

for (Documentation__kav kav:toDelete)
{
    KbManagement.PublishingService.archiveOnlineArticle(kav.knowledgeArticleId,null);

}

you are likely to hit the DML limits exception "Too many DML statements: 151"

3
  • Yeah I thought about doing that as an extreme measure but even that failed with something like "The operation is not allowed...." Thanks!
    – PepeFloyd
    Mar 5, 2013 at 13:30
  • You are trying this operation on a published article right ? I was able to archive a published article with " KbManagement.PublishingService.archiveOnlineArticle(kav.knowledgeArticleId,null)"
    – swatkat
    Mar 5, 2013 at 13:41
  • I can do that as well but not when inside a loop. Maybe I did something wrong, anyway, that wouldn't be a solution :(
    – PepeFloyd
    Mar 5, 2013 at 13:56
0

It's throwing below error for me.

FATAL_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 have checked all Object Permissions and System permissions for Knowledge Article, I have System Admin access.

Can Anyone help here?

1
  • 1
    Rather than asking a question in an answer space, please ask a new question. In your new question you can link to this question for reference if you like. (Please note that this "answer" will most likely be deleted. See information in Why and how are some answers deleted?)
    – Moonpie
    May 4, 2022 at 19:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .