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
Alan MonkAlan Monk 

Live agent case created by 'Automated process'

hi guys, I am looking for an example of a close case batch job for Live agent case created by 'Automated process'?
Best Answer chosen by Alan Monk
Akhil TandonAkhil Tandon
Hi Alan,

Below is an example batch job that you can use to close cases. This batch job can be executed using command "Database.executeBatch(new BatchCloseCase ());"


global class BatchCloseCase implements Database.Batchable<sObject> {
   public String query = 'select id, status from case where CreatedBy.Name=\'Automated Process\' and status != \'Closed\'';

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

   global void execute(Database.BatchableContext BC, List<sObject> scope)
   {
      List<Case> lstCase = new List<Case>();
      for(Sobject o : scope)
      {
          Case C = (Case) o;
          C.Status = 'Closed';
          lstCase.add(C);
      }
      update lstCase;
   }

   global void finish(Database.BatchableContext BC){
   }
}