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
prakashedlprakashedl 

BusinessHours and Test class

I am facing difficulties in writing test class. The main class logic reads the current date and time, reads the default business hours data, and performs functions based on the current date or time is within business hours or not. Also, it schedules jobs for end of business. My problem is since DML is not allowed in business hours, my coverage doesnt always remain constant and at times tests fail if i try to run it on weekends or holidays? Has anyone faced this before? Any suggestions to approach this problem would be very useful. 

CholericCholeric

Hi,

 

there might be better solutions but this should work.

 

Let your class have a global variable of Type Boolean (lets call it 'test') and initialize it with 'false'.

Add a function to the class that sets 'test' to true when it's called.

 

At the stage your're reading the current time, add an if clause asking if 'test' is true or not.

If it's true you set a time that suits your needs and if it turned false (thats the standard) it gets the current time.

 

 

Stefan