1

I'm sending out an Email notification using a Trigger every time an Appointment is set (an Event is created).

The User who's creating the Event is generally not the same as the Owner of the Event, i.e. the User will be setting up an appointment for someone else, who may be in a different timezone.

The issue I'm facing is that the outbound email shows the date/time of the appointment in the originating User's timezone.

I want to do some calculations to convert the date/time to the recipient user's time (using the difference between the recipient's timezone and the originator's timezone).

I'm seeking help on how to perform this conversion.

Thanks.

2 Answers 2

2

I recommend using the User.TimeZoneSidKey in your APEX. You can use that field to determine the timezone offset of both the creator user account and the owner user account.

Next, you'll need to perform some conversion math to determine the proper offset and obtain the correct/intended time value using these to data points.

2
  • Thanks for pointing me to the right direction. In the end, it turned out as simple as using the inbuilt DateTime.format function. Here's what I did: String startDateTimeAssigneeTZ = Evt.StartDateTime.format( 'yyyy-MM-dd HH:mm:ss', assignedUser.TimeZoneSidKey ); Commented Sep 24, 2015 at 14:53
  • Wow, much more elegant solution. Glad it helped!
    – James
    Commented Sep 25, 2015 at 12:51
3

this is piggy backing off of the previous comment but this is a good resource I've used when having to convert the timezone and perform the math - https://help.salesforce.com/apex/HTViewSolution?id=000005091&language=en_US

1
  • Thanks Jess. I came across that article as well - but the above approach worked out much simpler. Commented Sep 24, 2015 at 14:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .