What is the use of nextStartDate?

Starting from the specified target date, returns the next date when business hours are open. If the specified target date falls within business hours, this target date is returned.

Sample Code:

BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault = true];
Datetime nextStart = BusinessHours.nextStartDate(bh.id, system.today());
system.debug('Next Start Date is ' + nextStart);

If you execute the above code within the business hours(example if the business hours is 9 am to 6 pm and execute within the time frame), then it will return today’s date.

If you execute the above code outside the business hours(example if the business hours is 9 am to 6 pm and execute outside the time frame), then it will return next open business date.

Leave a Reply