I have created a scheduler class called scheduledInsert. The scheduler Job for this class is registered with following code
public class TestInsertTaskScheduler
{
public static testMethod void testInsertTaskScheduler()
{
scheduledInsert i = new scheduledInsert();
Datetime now = Datetime.now();
System.debug ('Datetime'+now);
String sch = '0 1 * * * ?'; // scheduled to execute every minute
system.schedule('Insert Task S3', sch, i);
System.debug ('After schedule');
}
}
The scheduled class code is
global class scheduledInsert implements Schedulable
{
global void execute(SchedulableContext SC)
{
System.debug('scheduled insert');
}
}
This job (Insert Task S3) does not display under Monitoring scheduled Jobs.
Also the Job does not execute at all.
What’s the mistake i am making?
I’m fairly sure it’s because you’re using a
testmethod. When you use atestmethodnothing is committed to the Salesforce database; so, it would make sense that the job doesn’t appear in theScheduled Jobssection. Try removing thetestmethodkeyword, run it again, and see if it appears.