Example #1
0
 private static String createScheduleJOB(
     String JobName,
     String cronExpression,
     Schedulable schedulable_class,
     TimeZone timeZone,
     DateTime startTime) {
   VirtualServerExecution start = VirtualServerExecution.start();
   try {
     CronTrigger cron = AModelType.newInstanceOfType(SO.CRON_TRIGGER);
     cron.setName(JobName);
     cron.setRunAs(InvocationContext.get().getCurrentSession().getUser());
     cron.setStartTime(startTime);
     cron.setPattern(cronExpression);
     cron.setSchedulable(schedulable_class);
     if (timeZone == null) {
       cron.setTimeZone(InvocationContext.get().getUser().getUserTimeZone());
     } else {
       cron.setTimeZone(timeZone);
     }
     cron.setNextFireTime(
         DateTime.newInstance(
             NextScheduleProvider.nextSchedule(cron.getPattern(), cron.getTimeZone())));
     DBResult insert = Database.insert(cron, new DMLOptions(DMLOperationType.THROW_ERRORS));
     return String.valueOf(insert._getId());
   } finally {
     start.finish();
   }
 }