You need to sign in to do that
Don't have an account?
EulogioGallo
Date.today() returning yesterday's date.
I have a scheduler that runs every day @9am PST that sends out birthday emails. However, when it ran this morning, it sent out emails to people who had birthdays yesterday. I'm using Date.today() to grab the date, and the debug log shows that this returned yesterday's date.
09:00:01.0 (19039191)|VARIABLE_ASSIGNMENT|[10]|this|{"listDay":"0x638eaffe","monthDayCount":"0x38f524b0","startDate":"0001-12-30T00:00:00.000Z","todaysDate":"2017-02-09T00:00:00.000Z"}|0x3f7a5e67
Anyone have a clue why? I checked my org's timezone settings as well as my user's settings, but everything is correctly set to 'Los Angeles'. Am I missing something?
09:00:01.0 (19039191)|VARIABLE_ASSIGNMENT|[10]|this|{"listDay":"0x638eaffe","monthDayCount":"0x38f524b0","startDate":"0001-12-30T00:00:00.000Z","todaysDate":"2017-02-09T00:00:00.000Z"}|0x3f7a5e67
Anyone have a clue why? I checked my org's timezone settings as well as my user's settings, but everything is correctly set to 'Los Angeles'. Am I missing something?
Salesforce schedules the class for execution at the specified time. Actual execution may be delayed based on service availability.
To solve your issue,
Date.today().addDays(1);
Hope it helps.
Regards,
Roshni
Thanks for replying! I've tried a variety of things, but I'm still having the same issue. Here are all the different ways I've tried to get an accurate date:
And here is how these variables are initialized when the Scheduler runs:
You'll notice it isn't even returning today's date, but last week's! Any help with this would be greatly appreciated, I'm really frustrated with this problem!
Hello Eulogio.
I'm having the exact same issue.
Did you ever found a way of fixing this? Thanks!
is this issue solved ? i m facing the same issue, can any one please help here?
Even I have faced the same issue with System.today() incorrect output in Scheduler class even after checking the time zone of Org. But I got the solution in mycase with the below approach,
I had scheduler class with a Date variable which is declared at the starting (outside the execute method). And I had scheduled it for a daily run at 4:00 AM PST on 23rd September 2020 for one week. But the problem is System.today() is printed 23rd September the whole week.
So I have put a debug inside the execute method to print my Date variable to see what is happening After adding the last line which is System.today() in direct debug, I could see this output is CORRECT. So as per my understanding when we schedule the scheduler, for the first run it getting called from the scratch and Date variable is getting saved somewhere and printing the same value whole week (From the second run it is just running the execute method).
So i changed my logic little bit, I declared "Date Todaysdate" from outside execute method and placed it inside execute and used it. Then my problem got solved. Hope this helps :)
Regards,
Ravi Gadi.