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
pbispbis 

TimeZone issue in Test Class

Hi,

 

I have a Trigger on Insert  which populates a field of Opportunity with Date.today().Time Zone of User and Company is CST.

In Test class assertion is written to check whether the field's value is Date.today() or not.

But the test class fails only for some time around 11:00 to 11:30 AM IST.

I have also put debug statement in test class and trigger to view the Date.today() and then I run the test class.But it shows wired behaviour .In test class Date.today() appears as date of the logged in user but in trigger around 11:00 to 11:25 AM IST  Date.today() is diplayed as the very next Day i.e. if it is 28 th Nov in CST then in trigger it displays 29 th Nov .The same test class works fine rest of the day.

 

Can someone help me.It creates issue since I cannot deploy changes to production in this time span.

alibzafaralibzafar
HI, You should use 'Running User' in your test Class, because your user timezone is set to IST thats why the test fails.