In our org, I have set-up business hours as 08:00-16:00 and timezone is GMT +2.
Saturdays and Sundays are blank which means they are holidays.
I then went in and set-up Holidays and have put the 24th, 25th and 26th of December as full day recurring holidays.
Now when I call the following method:
public static date verifySelectedDate (date userSelectedValue){
BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
DateTime dt = datetime.newInstance(userSelectedValue, Time.newInstance(12,59,59,59));
DateTime nextStart = BusinessHours.nextStartDate(bh.Id,dt);
System.debug('the value for datetime nextstart is '+nextStart);
date deliveryDate=nextStart.date();
return deliveryDate;
}
The issue is that when the userSelectedValue is "2018-12-22" (Saturday) the BusinessHours.nextStartDate method returns:
USER_DEBUG [59]|DEBUG|the value for datetime nextstart is 2018-12-24 06:00:00
This is incorrect as this is configured as a holiday in the system and should be skipped over. The value returned should be 2018-12-27 06:00:00.
Any ideas why the method is not taking holidays into consideration?