We have a scenario where we need to compare a date time field Last_Response_Date__c
against today function in SOQL
List<Contact> lstContactWithSamePhoneNo1 = [SELECT
Id,Last_Response_Date__c,End_Monitoring_Date__c,todayvalue__c
from Contact
where
Id ='123' AND (Last_Response_Date__c < TODAY)];
Our understanding was SOQL always run in UTC when date time fields are queried so it would compare UTC value of Last_Response_Date__c
value against today
in UTC and return the results.
Below is the record we are trying to query:
(Contact:{Id=123, Last_Response_Date__c=2020-05-20 00:13:06,
End_Monitoring_Date__c=2020-05-25 00:00:00})
Here is the issue below when the SOQL runs for any user:
- when we set users timezone to
"(GMT) Africa/Casablanca"
it doesnt return the record in the results - When we set users timezone to
"(GMT-04:00) Eastern Daylight Time(America/New_York)"
this record is returned in the results
Question:
- If the comparison is based on GMT why is it returning records in the second case above when set to EST timezone and not when set to GMT timezone?
- Does the results mean salesforce implicitly converts
today and Last_Response_Date__c
to user's time zone when the SOQL is comparing in the where clause and returns results.
Any inputs will be appreciated.