There are lots of posts regarding DateTime
format. But there are things for which I still can't find a solid answer.
- I Noticed that
Datetime
field values are converted into UTC and that converted values are kept in the back-end. When rendering those values in the UI, they will be converted back into the Organization/User's timezone. - Is it only the values which are coming directly from the UI (user entered) that are converted or it is any
Datetime
field values (such as the ones updated through controllers or triggers) that are converted? - In a
SOQL WHERE
clauses, what is the best way to useDateTime
fields to avoid potential confusing search results?
I recently noticed this behavior in Salesforce and managed to resolve the difficulties. But I really need to get a clear understanding of the ins-and-outs as a developer :).
Below are the assumptions for each of the aboves that I have taken based on my understanding up until now.
- Yes.
- All the fields will be converted. No matter if the value has been set by
DateTime.parse(string)
orDateTime.valueof(string)
or whatever. - Hope
DATE_TIME_FORMAULA(convertTimeZone(*dateTime*)) = myValue
will help here. Until now I've been able to manage withDate
fields since there was no need to filter based on time.
UPDATE
When retrieving data via a REST web service does this conversion also happen?