Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. global class TriggerManagementSchedulerJob implements Schedulable {
  2.    
  3.     global static void startSchedule() {
  4.        
  5.         TriggerManagementSchedulerJob sj = new TriggerManagementSchedulerJob();
  6.        
  7.                 String seconds = '0'; //Execute at Zero Seconds
  8.                 String minutes2 = String.valueOf(system.now().addMinutes(10).minute()); //Execute at every 10th minute of hour
  9.                 String hours = '*'; // Execute Every Hour
  10.                 String dayOfMonth = '*'; // Execute Every Day of the Month
  11.                 String month = '*'; //Execute only in November(11)
  12.                 String dayOfWeek = '?'; //Execute on all 7 days of the Week
  13.                 String year = '*'; //Execute only for year 2009
  14.                 String sch = seconds + ' ' + minutes2 + ' ' + hours + ' ' + dayOfMonth + ' ' + month + ' ' + dayOfWeek + ' ' + year;
  15.        
  16.         system.schedule('TriggerManagementSchedulerJob', sch, sj);
  17.     }
  18.    
  19.     global void execute(SchedulableContext sc) {
  20.        
  21.             if (LMSHelper.getCountApexJob() < 5){
  22.                
  23.                 List<Trigger_Assign_Status__c> assignStatuses = [SELECT
  24.                         Id, Trigger_Rule__c, Account__c, Contact__c, Case__c, Lead__c, Opportunity__c, User__c
  25.                     FROM
  26.                         Trigger_Assign_Status__c
  27.                     WHERE
  28.                         Status__c = :TriggerManagementHelper.TRIGGER_ASSIGN_STATUS_FAILED];
  29.                
  30.                 if (!assignStatuses.isEmpty()){
  31.                     Database.executeBatch(new TriggerManagementBatchAssign(
  32.                         assignStatuses
  33.                     ));                
  34.                 }
  35.                
  36.             }
  37.            
  38.             system.abortJob(sc.getTriggerId());
  39.        
  40.             TriggerManagementSchedulerJob.startSchedule();
  41.        
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement