+ Start a Discussion
Vijay Kumar Rebbala 1Vijay Kumar Rebbala 1 

Execute schedule class using Developer console

I need to help on how to execute the schedule class from Developer console and also please review the code for any mistakes.

//Scheduler Class
global class Scheduler_DeleteoldCases implements Schedulable{
  global void execute(SchedulableContext SC) {
     DeleteoldCases gm = new  DeleteoldCases() ; 
  }}


global class DeleteoldCases{
    Public void DeleteoldCases(){
        List<Case> QueryCases = [SELECT Id FROM Case WHERE Case.CreatedDate < LAST_N_MONTHS:18 ORDER BY CreatedDate ASC  LIMIT 9000];
        If (QueryCases == null){return; }
        system.debug('********List of Cases********'+QueryCases);
        try{
            delete QueryCases;
        }catch(DmlException e) {
            System.debug('An unexpected error has occurred: ' + e.getMessage());
        }  }}




Best Answer chosen by Vijay Kumar Rebbala 1
Vivek DeshmaneVivek Deshmane
Hi,
You can schedule your class for every 10 minutes as below.Let me know if it works for you.
Scheduler_DeleteoldCases   s = new  Scheduler_DeleteoldCases (); 
String sch = '0 0 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob1', sch, s);

String sch1 = '0 10 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob2', sch1, s);

String sch2 = '0 20 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob3', sch2, s);

String sch3 = '0 30 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob4', sch3, s);

String sch4 = '0 40 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob5', sch4, s);

String sch5 = '0 50 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob6', sch5, s);

Best Regards,
-Vivek
 

All Answers

Vivek DeshmaneVivek Deshmane
Hi,
You can schedule your class for every 10 minutes as below.Let me know if it works for you.
Scheduler_DeleteoldCases   s = new  Scheduler_DeleteoldCases (); 
String sch = '0 0 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob1', sch, s);

String sch1 = '0 10 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob2', sch1, s);

String sch2 = '0 20 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob3', sch2, s);

String sch3 = '0 30 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob4', sch3, s);

String sch4 = '0 40 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob5', sch4, s);

String sch5 = '0 50 * * * ?';
System.schedule('Scheduler_DeleteoldCasesJibJob6', sch5, s);

Best Regards,
-Vivek
 
This was selected as the best answer
Vijay Kumar Rebbala 1Vijay Kumar Rebbala 1
DML Operation is not performed nor did the query. Can you find the fault PLZ. Debug Log


34.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
15:20:00.023 (23500836)|PUSH_TRACE_FLAGS|[EXTERNAL]|01pR0000000CNcR|Scheduler_DeleteoldCases|APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,DEBUG;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
15:20:00.023 (23554900)|EXECUTION_STARTED
15:20:00.023 (23567558)|CODE_UNIT_STARTED|[EXTERNAL]|01pR0000000CNcR|Scheduler_DeleteoldCasesJibJob3
15:20:00.039 (39871210)|METHOD_ENTRY|[1]|01pR0000000CNcR|Scheduler_DeleteoldCases.Scheduler_DeleteoldCases()
15:20:00.039 (39889993)|METHOD_EXIT|[1]|Scheduler_DeleteoldCases
15:20:00.040 (40010244)|SYSTEM_METHOD_ENTRY|[6]|System.debug(ANY)
15:20:00.040 (40048688)|USER_DEBUG|[6]|DEBUG|**************scheduler class executed*****************************
15:20:00.040 (40061338)|SYSTEM_METHOD_EXIT|[6]|System.debug(ANY)
15:20:00.060 (60549148)|METHOD_ENTRY|[1]|01pR0000000CNcM|DeleteoldCases.DeleteoldCases()
15:20:00.060 (60569711)|METHOD_EXIT|[1]|DeleteoldCases
15:20:00.060 (60604279)|CONSTRUCTOR_ENTRY|[7]|01pR0000000CNcM|<init>()
15:20:00.060 (60675689)|CONSTRUCTOR_EXIT|[7]|01pR0000000CNcM|<init>()
15:20:00.062 (62209463)|CUMULATIVE_LIMIT_USAGE
15:20:00.062 (62209463)|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
15:20:00.062 (62209463)|CUMULATIVE_LIMIT_USAGE_END
15:20:00.062 (62266838)|CODE_UNIT_FINISHED|Scheduler_DeleteoldCasesJibJob3
15:20:00.063 (63809677)|EXECUTION_FINISHED
15:20:00.151 (151547191)|POP_TRACE_FLAGS|[EXTERNAL]|01pR0000000CNcR|Scheduler_DeleteoldCases|