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

1

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);
| improve this answer | |
  • 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 '13 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 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"

| improve this answer | |
  • 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 '13 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 '13 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 '13 at 13:56

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.