Does Date.addDays() method skip the weekends based on the Org’s Business Hours settings

apexbusinesshoursdate

For example when I use Date.addDays(1) for a task's due date. I realized if the next day falls into a weekend both Sat and Sun are skipped and it adds 1 workday (which is three days count). Now, this is great cause I was thinking of how to accomplish this in the first place but when I saw this result and referred to the official date class doc I didn't find this feature being mentioned. I also checked our org's Business Hours settings and sure weekends are not set as work days. So I just came over here to get a confirmation on what I'm observing is correct and hopefully, help someone who has the same question in the future. Thanks.

Here's a sample code that shows how I'm calling the method and checking the result,

Task t = new Task(
    OwnerId = ownerId,
    Priority = 'High',
    ActivityDate = Date.today().addDays(1), //this is where I'm setting the Due Date
    WhoId = contactId,
    Type = 'Type',
    Description = 'Description',
    Subject = 'Subject',
    Status = 'Status'
);
insert t;

and to check the results I use the UI in Salesforce to navigate into the Tasks table and open this task I created above and look at the Due Date field.

Best Answer

It does not interact with your Business Hours at all. It just adds days. From the documentation on the Date class:

addDays(additionalDays)
Adds the specified number of additional days to a Date.

Related Topic