2

I copied an existing scheduler class that we have that runs every hour. I want to do the same thing and run every hour for my batch job. How can I kick it off to actually show up on the scheduled apex page?

I've saved the class in the sandbox and compiled it. However, I can't seem to find where to start it. I've read some posts where it talked about using anonymous apex in the dev console but it never gives examples of what code to use.

How can I start the process to start running in the scheduled apex page?

Example code:

global class NPD_Scheduler_RevenuePipelineSchedule implements Schedulable {
/* Start - Variables */
Integer batchSize;
/* End - Variables */

/* Start - Constructor */
global NPD_Scheduler_RevenuePipelineSchedule(Integer batchSize){
    this.batchSize = batchSize;
}
/* End - Constructor */

/*
    @MethodName : execute.
    @param      : SchedulableContext
    @Description: This Class calls Batch class
*/
global void execute(SchedulableContext sc)
{
    try {
        NPD_Batch_RevenuePipelineScheduleUpdater objBatch = new NPD_Batch_RevenuePipelineScheduleUpdater();
        System.debug('\n\nSchedule Job');
        Database.executeBatch(objBatch, batchSize);             
    }
    catch(Exception e)
    {
        //Show exception in debug logs if any
        System.debug(LoggingLevel.error, '### Exception: ' + e);
    }
}
/* End */

public static void scheduleBatch() 
{
    scheduleBatch(200);
}

/**
* @MethodName : scheduleBatch
* @Param        : NA
* @Description: static method to run batch hourly
**/
public static void scheduleBatch(Integer batchSize) 
{
    System.schedule('Revenue Pipeline Scheduler', '0 0 * * * ?', new NPD_Scheduler_RevenuePipelineSchedule(batchSize));
}

}

1 Answer 1

3

Your code includes a static method to schedule it so

In your case you would simply execute

NPD_Scheduler_RevenuePipelineSchedule.scheduleBatch();

If you want a custom batch size use the following and pass in what you want the batch size to be

NPD_Scheduler_RevenuePipelineSchedule.scheduleBatch(200);

If you did not have that method you would use the system.Schedule() method like exists in you code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .