I'm currently running a batch Apex job every day that processes payments for all Opportunities due to close on a given day. This is working fine, but we are soon expanding into other timezones, and I'm not sure how it will work.

I want to run a SOQL query for all Opportunities closing today, but "today" is different in the US and Australia (the two countries we are operating in). My user account is based in Australia, so currently it will pick up Opportunities one day early, which will be incorrect.

The CloseDate field is a Date rather than a DateTime, meaning it has no timezone. I guess this means that whether or not an Opportunity closes "today" depends on the user's timezone -- correct?

If that's the case, is it possible to modify this behaviour in Apex? I guess I could run the batch job under a user in the right timezone, but I don't really want to have to do that.



  • Can you use date literals in soql, i guess it takes care of timezone as well. Otherwise its very complicated to do that in apex.
    – Raul
    Mar 14, 2017 at 9:50

1 Answer 1


Ahh that's tricky, I am afraid you will have to manually take care of that.

SOQL queries takes care of the timezone as per the running user, but in your scenario it will be Australia.

I reckon, you would need to identify all qualifying opportunities based on the GMT time (Setup the batch running user with GMT locale). Later use the opportunity owner and his locale to identify the timezone difference and process that in apex.

  • Brilliant, thanks so much for that. I didn't think to use the opp's owner, that's exactly what I've done and it's working well. Mar 15, 2017 at 5:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .