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

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(...);
  • I knew it was something simple. Thank you! – jonnybro Nov 25 '19 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.