In a multitenancy environment, multiple customers share the same application, running on the same operating system, on the same hardware, with the same data-storage mechanism. The distinction between the customers is achieved during application design, thus customers do not share or see each other's data.
global class MyScheduler implements Schedulable {
private final Id recordId;
public MyScheduler(Id recordId){
this.recordId = recordId;
}
global void execute(SchedulableContext sc){
System.debug('**** recordId: '+this.recordId+' date: '+Date.today());
// ****** Do your logic here ******
// abort to execute it only once
System.abortJob(sc.getTriggerId());
}
public static void schedule(){
String hour = String.valueOf(Datetime.now().hour());
String min = String.valueOf(Datetime.now().minute() + 1);
String ss = String.valueOf(Datetime.now().second());
//parse to cron expression
String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';
MyScheduler sc = new MyScheduler('0018F00000ABA3AQBX');
String name = 'Submited at: '+String.valueOf(Datetime.now())+ ' next: '+nextFireTime;
System.debug(name);
System.schedule(name, nextFireTime, sc);
}
}
MyScheduler. schedule();