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

batch Apex to escalate cases

I have fields like case status and date/time opened in the cases object.

If the date/time opened is more then one hour and still the status is new and the status is not approved or rejected the case should get escalated.

On escalation the status should change to escalated and the user should get a mail of escalated case assignment.


I am new to apex can someone please help me to write a batch apex for this.




Try escalation rules.


I tried using escalation rules but that is not working.


Now i am trying to use batch apex for the same so that i can use apex scheduler i have written the apex class as follows

global class CaseEscalationRules implements Database.Batchable<sObject> {

          global Database.QueryLocator start(Database.BatchableContext BC){

                             return Database.getQueryLocator([SELECT CaseNumber, CreatedDate,Status

                                                 FROM Case ]);



          global void execute(Database.BatchableContext ctx, List<Sobject>scope){

                           List <Case> ca = (List<Case>)scope;

                          for(Integer i = 0; i < ca.size(); i++){

                          if(System.Today() - ca.CreatedDate >=1 && ca.Status!='Closed' )


                                   String emailMessage = 'The case '

                                            + Case.CaseNumber

                                           + ' has been ecalated '

                                           + ' Please look into the case '

                                           + 'Thankyou';

                                     Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

                                 String[] toAddresses = new String[] {''};


                                 mail.setSubject('Case Escalation');


                                 Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });

                                 Case.Status = 'Escalated';


            update ca;


          global void finish(Database.BatchableContext ctx){




for this code i am getting an error: Error: Compile Error: Expression cannot be assigned at line -1 column -1 


Also can someone please help me with the 'If condition' where i need to check whether the CreatedDate of a case is more than one hour .