[SalesForce] How to get the current timestamp using SOQL query
I want to know the timezone of the timestamp value in systemmodstamp column in my SF objects.
Best Answer
Date values are stored in UTC time format in Salesforce, the timezone is only applied when the date is displayed. If you are in Apex, you can use the various methods it provides to return an automatically adjusted value or the GMT value.
Remember that dateTime field values are stored as Coordinated Universal Time (UTC). When one of these values is returned in the Salesforce application, it is automatically adjusted for the timezone specified in your organization preferences. Your application may need to handle this conversion.
You can retrieve the current time zone using the UserInfo class.
The datetime will be converted to the logged-in users local timezone if you use apex:outputField to render your date.
You have to use apex:outputText if you don't want any conversion, which means it will be shown in GMT.
It seems you want to convert the datetime to the record creator's timezone for other users? I am not sure why you would want to do that, but if yes you will have to use Apex to get the timezone of the record creator and convert that before displaying to other users.
When trying to sync, you don't need to worry about the mechanics of determining the correct time to use. Instead, just use getUpdated (/vXX.X/sobjects/ObjectName/updated?start=X&end=Y in the REST API), which will return a list of ID values you can retrieve from and a value called lastDateCovered, which is the next start time that you should use in your replication. In flight requests won't be included, but the lastDateCovered attribute will be offset by any in flight requests-- your next sync request will automatically include any values you missed in the last request because they were still in flight (not fully committed). The only issue you have to worry about is selecting the correct first initial sync date/time. For more information, I'd suggest taking a look at the SOAP API Developer's Guide under Data Replication, and the Force.com REST API Developer's Guide for REST-specific considerations.
Best Answer
Date values are stored in UTC time format in Salesforce, the timezone is only applied when the date is displayed. If you are in Apex, you can use the various methods it provides to return an automatically adjusted value or the GMT value.
You can retrieve the current time zone using the UserInfo class.