salesforceapex-codevisualforce

Debugging Schedulable Job in apex salesforce


i am trying to run a schedulable job i never used schedulable jobs in salesforce

here is my code

global class scheduledMerge implements Schedulable{
   global void execute(SchedulableContext SC) {
      System.debug('Hello World'); 
   }
}

          created a cusom controller
public class schedulableMerge{

public schedulableMerge(){

}
public PageReference Hello(){
scheduledMerge m = new scheduledMerge();
        String sch = '0 10 * * 1-12 ? *';
        system.schedule('Merge Job', sch, m);
        return null;
}

}

and visualforce page is

<apex:page controller="schedulableMerge">
  <!-- Begin Default Content REMOVE THIS -->
    <h1>Congratulations</h1>
  This is your new Page
  <!-- End Default Content REMOVE THIS -->
  <apex:form >
  <apex:commandButton value="Press it" action="{! Hello}" />
</apex:form>

</apex:page>

when i press button press it there is a job in All schedulable job but there is only one option delete with it.No option of manage. i think this job should run in every 10 minutes .i saw debug logs from Monitoring>Debug Log it is showing no log. can you please tell what is the expression for running job in every one minute and where to see debug logs?? my aim is to see working of schedulable job


Solution

  • Good news - you don't need a visualforce page and controller. Bad news - you can't schedule jobs with 1 minute intervals. I think 5 mins is the minimum (but I'm not sure, you'd have to experiment with it).

    How to run it (once) on demand? From Developer Console or Eclipse's "Execute Anonymous" block.

    Make sure your user is added to debug logs and simply force running of the execute method you had to implement as part of the interface:

    scheduledMerge sm = new scheduledMerge();
    sm.execute(null);
    

    Experiment with the cron expressions after you're satisfied that one run completes succesfully. If you're fine with frequency once a day - you don't need these expressions at all, go to Setup -> Develop -> Classes and click [Schedule Apex]. Only if you need multiple runs a day use code to schedule the class.

    Last but not least - go to setup and type "Apex jobs" in the search. You should see info of all asynchronous tasks performed recently (scheduled jobs, batches, @future methods etc)