You need to sign in to do that
Don't have an account?
How to make cron job for last day of month
Hi folks,
Running into an error and not quite sure why. I am trying to schedule a cron job for the last day of the month. My cron expression is:
0 30 22 L * ?
Which should fire at 10:30 PM on the last day of the month, for every month, specifying no day of week as far as I can tell from the documentation:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
However, I am getting the error:
"Support for specifying 'L' and 'LW' with other days of the month is not implemented"
I was getting this error before when I WAS trying to specify some days of the month in addition to the last day, but now I am stumped as to why I am hitting this when I am only specifying "L" in the Day of Month portion of the cron expression. Any ideas would be appreciated.
Thanks,
Chris
As I understand from your question, you are trying to schedule the job two days in a month.
pls read this article : https://stackoverflow.com/questions/35625827/quartz-setting-cron-expression-to-run-on-the-1st-and-last-day-of-month (https://stackoverflow.com/questions/35625827/quartz-setting-cron-expression-to-run-on-the-1st-and-last-day-of-month)
and you need to define two expression for two days to execute job : (0 1 0 15 * ?) (0 1 0 L * ?)
Hope this will help you.
Thanks,
Mukul
To make cron job for last day of month you have to use chrone expression in apex. To know about
chrone expression please see below link.
https://www.biswajeetsamal.com/blog/schedule-apex-jobs-using-cron-expression-in-salesforce/
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi
Thanks for the replies, but those do not answer the question here. Mukul, I had read the article you are referring to prior to posting here. I am trying to only create a cron job for the last day of the month, no other days. I just mentioned that I had tried other days in the same expression before and I have already determined that would not work. So, the question here is how do you schedule a cron job for only the last day of the month and no others. in your example, this was "0 1 0 L * ?" in my example it was "0 30 22 L * ?". Both should work according to the documentation from salesforce located here:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
That brings me to Suraj. Suraj, thank you for your reply as well. However, I am well aware that I need a cron expression for this already. My question is why my particular cron expression does not seem to be working. It should from the documentation I saw from salesforce posted above. The link you posted seems to be nothing other than copying and pasting the same information from salesforce into a blog right down to having the same examples. If there was something else that I did not see there that answers how to schedule a cron job for the last day of the month and why my cron expression is hitting the error from my original post, please let me know and it would be greatly appreciated.
Thanks,
Chris
Thanks for the explanation.
Note: About error that you are getting this can be an issue of cache try to clear cache or delete the class and create again the class at setup -> apex class.
Below is just my understanding on execution :
I have tried in my personal org and schedlued with this expression '0 0 0 L * ?'
below is class I have used to schedule :
public class scheduleFamBatchclass implements Schedulable {
public string scheduleFamBatchclass1() {
scheduleFamBatchclass reminder = new scheduleFamBatchclass();
String sch = '0 0 0 L * ?';
return System.schedule('test', sch, reminder);
}
public void execute(SchedulableContext sc) {
FAM_Delegation_BatchClass b = new FAM_Delegation_BatchClass();
database.executebatch(b);
}
}
As you can see in screenshot next schedule date is 29/sep/2021, so this is taking last date as 29th sep because sep month is 30days.
Thanks,
Mukul