2

I need to schedule the class below to run every 10 minutes.

What changes do I need to make to my class below?

global class Change_Inc_To_Resolved Implements Schedulable{
global void execute (SchedulableContext sc)
{
    ChangeStatusToResolved();
}
public void ChangeStatusToResolved()
{   
    List<BMCServiceDesk__Incident__c> UpdateStatus = new list <BMCServiceDesk__Incident__c>();
    UpdateStatus = [SELECT Id, BMCServiceDesk__FKStatus__c FROM BMCServiceDesk__Incident__c WHERE Status_Updated__c = FALSE AND BMCServiceDesk__FKStatus__c = 'a4Bw0000000CcCNEA0' LIMIT 100];
    for(BMCServiceDesk__Incident__c up: UpdateStatus)
    {   
        up.BMCServiceDesk__FKStatus__c = 'a4Bw0000000CcCNEA0';
        updatestatus.add(up);
    }
    update UpdateStatus;
}
}

I've seen the code below in a link https://developer.salesforce.com/forums/?id=906F00000008yFvIAI , do I use this in conjunction with my class above? If so, what changes do I need to make to it?

global class scheduledTest implements Schedulable{

    global void execute(SchedulableContext SC) {

        RecurringScheduleJob.startJob();  

        String day = string.valueOf(system.now().day());

        String month = string.valueOf(system.now().month());

        String hour = string.valueOf(system.now().hour());

        String minute = string.valueOf(system.now().minute() + 10);

        String second = string.valueOf(system.now().second());

        String year = string.valueOf(system.now().year());



        String strJobName = 'Job-' + second + '_' + minute + '_' + hour + '_' + day + '_' + month + '_' + year;

        String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;

        System.schedule(strJobName, strSchedule, new scheduledTest());

}

}
  • 1
    Your title says every 10 minutes, but your question says every 5 minutes. Which one is it? – Derek F Apr 20 '17 at 12:34
7

You have to schedule your batch for 6 times, if you want to run batch for every 10 mints.

System.schedule('Scheduled Job 1', '0 0 * * * ?', new scheduledTest());
System.schedule('Scheduled Job 2', '0 10 * * * ?', new scheduledTest());
System.schedule('Scheduled Job 3', '0 20 * * * ?', new scheduledTest());
System.schedule('Scheduled Job 4', '0 30 * * * ?', new scheduledTest());
System.schedule('Scheduled Job 5', '0 40 * * * ?', new scheduledTest());
System.schedule('Scheduled Job 6', '0 50 * * * ?', new scheduledTest());
| improve this answer | |
  • Thanks very much for your help Ratan, would you mind editing the post so that it's obvious to a no code admin that they need to do this in the developer console, and that they must click "Debug" then "Open Execute Anonymous Window" followed by typing the code you've mentioned. This would've made it far easier for me to understand – Glenn Daly Apr 20 '17 at 14:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.