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
RockersRockers 

How to capture the scheduled start time of the apex class?

Hi Friends,

 

                 I scheduled on apex class which is used to perform the Batch Operations. In that, i need to capture the start time of the scheduled job of the apex class and wants to use in the apex code to send an email after completion of Batch Process.

 

              I tried capturing the starttime from CronTrigger Object. But, it is not giving the correcct value.

 

              I scheduled the apex class by using the Schedule Apex. In my sçhedule class, i just call the Batch Apex Class to perform the Batch Operation. In that, i am just using the below query to get the starttime of the schedule apex.

 

//Schedule class//

 

Global class POSProcessScheduler implements Schedulable{

        

Global void execute(SchedulableContext ctx) {
        
CronTrigger ct = [SELECT Id, CronExpression, StartTime, TimesTriggered, NextFireTime FROM CronTrigger WHERE Id =   :ctx.getTriggerId()];
        System.Debug('Schedule StartTime : '+ct.StartTime);
        System.Debug('TimesTriggered : '+ct.TimesTriggered);
        System.Debug('NextFireTime : '+ct.NextFireTime);
        
        POSProcessBatch batch = new POSProcessBatch();
        batch.ScheduledTime = ct.StartTime;
        Database.executeBatch(batch,200);
        
     }

}

            

Please suggest me, how to capture the start time of the schedule apex.

 

Regards,

Phanikumar