You need to sign in to do that
Don't have an account?
bryano
Getting Current DateTime in Scheduled Apex
So I have an Apex class that is scheduled to run every hour. In my class I have 2 class level variables:
public DateTime NOW = datetime.now();
public DateTime LAST_HOUR = NOW.addHours(-1);
I setup the scheduled job via execute anonymous on 11/30/2012 4:38 PM. The class has been running every hour however, my 2 DateTime variables are never getting updated. NOW is always 11/30/2012 4:38 and LAST_HOUR is 11/30/2012 3:38 PM. I'm using these 2 variables to filter on CreatedDate.
Anyone know how I can get NOW to be the current time when the job runs?
Hi bryano,
I think you can query on the "AsyncApexJob" sobject it will give you all information about uour running apex jaob like (CompletedDate,CreatedDate etc) using this information you can achive your functionlality, I believe it should work.
--
Thanks
Usman
Hi
i don't think nothing wrong what you using.
try this
Public datetime NOW = system.now();