Line: 3, Column: 1 System.StringException: Unexpected end of expression.


public class OppSchedule implements schedulable{
    public void execute(SchedulableContext sc){
        List<Opportunity> opp=[select id,name,stageName from Opportunity where stageName='closedWon'];
        for(Opportunity o:opp){
            if(o.stageName =='closedWon'){
                delete o;

Anonymous Script:

System.Schedule('mj','0 0-5 13 ?  * ',new OppSchedule());
  • 1
    You should never ever include DML Statements in a loop. Here, your if statement is also completely redundant. Simply call delete [SELECT Id FROM Opportunity WHERE ...].
    – Adrian Larson
    Jun 4 '19 at 17:04

cron expressions have 6 or 7 parts, and you've only included five.

From the Apex Scheduler documentation (emphasis mine)

The System.Schedule method takes three arguments: a name for the job, an expression used to represent the time and date the job is scheduled to run, and the name of the class. This expression has the following syntax:

Seconds Minutes Hours Day_of_month Month Day_of_week Optional_year

The seventh part of the format is (as the slot name implies) optional, but using a dash to specify a range is only valid for the Day_of_month, Month, Day_of_week, and Optional_year parts.

The root of the issue is that you've tried to use a range for the minutes part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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