Skip to main content
I'm trying to set up a class where there will be a job that will run twice a day. To search for all knowledge, if you have any with PublishStatus = 'Online' and the expected filing date for today I would like to change PublishStatus to "Archived" and ArchivedDate for today. However it is returning that I cannot save the fields. can you help me?

 

My class code:

 

public class KnowledgeController {

 

    

 

    public static KnowledgeController getInstance(){

 

        KnowledgeController instance = new KnowledgeController();

 

         return instance;

 

    }

 

    

 

    private void KnowledgeController() {

 

        

 

    }

 

    

 

    public void validaArquivamento(){

 

        

 

        Date todaysDate = system.today();

 

        

 

        List<Solucoes__kav> lstKnowledge = [SELECT Id,

 

                                            ArchivedDate,

 

                                            BR_PrevisaoArquivamento__c,

 

                                            PublishStatus

 

                                            FROM Solucoes__kav 

 

                                            WHERE PublishStatus = 'Online' and BR_PrevisaoArquivamento__c =: todaysDate];

 

        

 

        if(lstKnowledge.size() > 0){            

 

            for(Solucoes__kav knowledge : lstKnowledge){

 

                    knowledge.PublishStatus = 'Archived';

 

                    knowledge.ArchivedDate = todaysDate;

 

                    

 

                    update knowledge;

 

            }

 

        }

 

    }

 

}

 

Class to automatically archive Knoledge in Lightning
1 件の回答
  1. 2020年6月19日 22:57
    Hi,

     

    Have a look on relevant article.

     

    Update Knowledge base articles with Data Loader

     

    https://help.salesforce.com/HTViewSolution?id=000233637

     

    It's not possible to update an article's PublishStatus via the Data Loader and it's necessary edit each article you would like to update to create a draft version.
0/9000