0

I am struggling with an issue to convert input time on salesforce UI (Assumed time in customer state) and on save of the record display this time into User's time zone. Eg. Agent with Sydney/Melbourne timezone input 12:00 PM time for customer in Perth and when this record is saved it should display 2:00 PM for the user in Sydney/Melbourne time zone.

I am able to achieve this, however it is done by adding difference of timezone for customer and User both.

I am looking for a way where i may not need to use this difference in offset and user time zone in calculation and can be achieved directly through methods provided by DateTime and TimeZone class in salesforce

0

The best/default approach to this problem is that the DateTime values in the database are stored using UTC (used to be called GMT) time. Each User in Salesforce can have their own timezone set, and many user interface input and output components automatically respect that timezone and apply the timezone offset e.g. adding on input and subtracting on output. Example components are apex:inputField and apex:outputField.

Unfortunately this subject appears to not be well documented by Salesforce (at least based on two minutes of Googling).

| improve this answer | |
  • Thanks Keith! This is actually a standard custom object detail page where User input time of service in customer's time zone .The issue is in system it is stored as a UTC as per user's timezone, which is salesforce's standard behaviour. I am using a trigger handler to check difference of customer time zone offset and user's time zone offset and add this back to datetime field to display to user. Is there any other better and reliable solution to this which can give same result by using classes and methods provided by salesforce. – Nitesh Jul 7 '18 at 23:33
0

The question of how to deal with a customer time zone different from the user's is really something Salesforce has nothing built-in to handle. I suggest creating utilities that you can reuse in multiple situations.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.