function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Peter KayePeter Kaye 

Update date time field from a date and a time as text

I want to update a datetime field from a date field and a time pick list.  The SF system has users in a fixed time zone with a twice yearly daylight saving adjustment which I think means I cannot use a formula and therefore require an Apex Trigger on BeforeInsert and BeforeUpdate.  It's more than 12 months since I wrote any Apex so I hope someone can get me started on this !   Thanks.
RohRoh
Helo Peter,
Yes we can do it, please follow the below methodology.

IF (OR(ISPICKVAL(countryField,'United Kingdon'),ISPICKVAL(countryField,'Australia')),
TEXT( DAY( datefield) ) & "/" & TEXT( MONTH( datefield) ) & "/" & TEXT( YEAR( datefield) ),
TEXT( MONTH( datefield) ) & "/" & TEXT( DAY( datefield) ) & "/" & TEXT( YEAR( datefield) ))


Please create one formula field and return type as text and include the above formula
The above example has formula for to check if country is United Kingdom or Australia to return one format , else return US format.
You can include as many countries you want and write the If,Else logic as needed.

Please select this as the best answer, if it has answered your question.

Thanks,
Rohit Alladi
Peter KayePeter Kaye
Thanks Rohit.

The formula you provide gives a way to setting different date formats based on a SF country location database field which is useful.  However my problem relates to the time field I need to build a date time value and requires access to the GMT adjustment value currently applicable for the user. So simply manipulating a string such as 14:00 will be treated as a GMT time when used to form the date time value.  If there is a daylight saving adjustment of an hour then the datetime value will be one hour out. SF documentation says that this is very difficult to handle with a formula and they advice Apex code - which is what prompted this post.
RohRoh
Hello Peter,
Sorry for delayed reply, but yes i would ask you to construct a design where your data would be dictated by an object record which has the offset variable (usually -700 , +300) etc per each country. Now, in Apex code you should always get this data out and run math to get the final out put.
By this the timezone variable is dynamic and you would not have edit the code everytime.

Please select this as the best answer, if it has answered your question.

Thanks,
Rohit Alladi