function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC coderSFDC coder 

Unable to schedule through apex code

Hi all,

i have a requirement where in i need to schedule a batch class using apex code.
The scheduled time & date depends on the input provided by the user in the DateTime custom field

This is what i have done till now
            todaysTime=Date.today();
            secs=String.valueOf(todaysTime.second());
            mins=String.valueOf(todaysTime.minute());
            hrs=String.valueOf(todaysTime.hour());
            sday=String.valueOf(todaysTime.Day());
            smonth=String.valueOf(todaysTime.month());
            syear=String.valueOf(todaysTime.year());
            sweek=todaysTime.format('E');
            
            finalString=secs+' '+mins+' '+hrs+' '+sday+' '+smonth+' '+sweek+' '+syear;
   
OUTPUT:*** final string0 0 1 3 12 Wed 2014


However i get an error as
Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.
I want the batch class to be executed as per the time i have fetched in the string
Can anyone please help?
Swati GSwati G
You can either provide day of week or day of month. so, instead of day of week provide ?
lakslaks
Hi,

The optional_year parameter should come after the Day_of_week parameter in the CRON expression.
Do check if that resolves your issue.

Regards,
Lakshmi.