0

For some reason when I attempt to use the BusinessHours.isWithin method within Salesforce I get the following error:

Compile failure on line 4, column 34: Method does not exist or incorrect signature: void isWithin(Id, Datetime) from the type BusinessHours

Here is the simple code I used to generate this error in anonymous apex:

BusinessHours businessHours = [SELECT Id FROM BusinessHours WHERE IsDefault=TRUE];
System.debug('Business Hours:' + businessHours);

Boolean isWithin = BusinessHours.isWithin(businessHours.Id, System.now());
System.debug('isWithin:' + isWithin);

Any ideas on why I'm getting this error?

1 Answer 1

1

You have introduced a naming conflict here:

BusinessHours businessHours = [...];

Any lines below this will reference the record you have queried, not the class you are trying to reference. You can either fix it by naming your record something else and avoiding the conflict altogether, or referencing the BusinessHours class prefixed with System. to disambiguate.

Boolean isWithin = System.BusinessHours.isWthin(...);
1
  • I knew it was something simple. Thank you!
    – jonnybro
    Commented Nov 25, 2019 at 19:28

You must log in to answer this question.

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