2

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.

4
  • It's not clear how you're invoking Date.addDays() and verifying the result. Please edit your question and provide a Minimal, Reproducible Example
    – identigral
    May 26, 2022 at 20:33
  • 1
    Thanks for the edit. As shown, this won't compile due to Date.addDays
    – identigral
    May 26, 2022 at 20:42
  • 1
    Just fixed the error it's Date.today().addDays(1)
    – Bahman.A
    May 26, 2022 at 20:44
  • 1
    As shown, this issue is not reproducible. Date.addDays certainly does not take business hours or business calendar into account. Two possibilities of what you might be seeing: you have another process (trigger, flow, ...) that overwrites the due date or the timezone delta. UI will render the date in the timezone of the currently logged in user which could be different from the user attached to execution context. Could the latter difference push you over the weekend? If Date.today() is a Friday, +1 is Sat and timezone delta is more than 12 hours, it's possible.
    – identigral
    May 26, 2022 at 20:57

1 Answer 1

2

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.

You must log in to answer this question.

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