Sub topic 7
Business Hours and Holidays
This chapter covers how Salesforce models the times when your support team works. It also covers how those times control escalation timing. It assumes you can navigate Setup, understand case lifecycle and status, and know what an escalation rule is at a high level. The next chapter builds the escalation rule itself. This chapter prepares the clock it runs on.
Why business hours matter
An escalation rule measures how long a case has been open. If the team works Monday to Friday, 9:00 to 17:00, a case created at 16:55 on Friday should not escalate at 17:25 on Friday. It should escalate after the team has had time to work on it. Business hours let Salesforce count only the working time.
Business hours also apply to other features, such as entitlement processes and milestones. Those are covered in a later chapter. For this chapter, the focus is on escalation rules.
What a business hours record contains
A business hours record is a named set of settings. You create it in Setup by searching for Business Hours. Each record has these parts:
- Name and active flag. Only active records can be used by rules.
- Time zone. The zone in which the working hours are defined. Salesforce converts case timestamps to this zone when it counts working time.
- Daily hours. A start and end time for each day of the week. You can leave a day blank, which makes it a non-working day. Setting 24 hours means the day runs all day.
- Default flag. One record in the org is the default. It is used when a rule or process does not name a record.
- Holidays. A list of holiday records linked to the business hours.
You can create several records. For example, a team in Dublin and a team in Sydney would each have their own, with different time zones and daily hours. A premium support tier that is staffed around the clock could use a 24-hour record.
Holidays
A holiday is a date or a recurring date on which the team does not work. Holidays are separate records that you link to one or more business hours records.
A holiday has these properties:
- Name and description.
- Date. Either a single date, or a date range if the holiday spans several days.
- All day or specific hours. An all-day holiday removes the whole day. A holiday with specific hours removes only that time window, so you can model a half day.
- Recurrence. A holiday can repeat yearly, monthly, or weekly, and so on. A recurring holiday means you do not need to recreate it every year.
To use a holiday, open the business hours record and add the holiday in the Holidays related list. One holiday can be linked to several business hours records. A holiday that is not linked to any record has no effect.
How the clock runs
When a rule entry specifies a business hours record, the escalation age is counted in working time only. Consider an escalation rule entry that escalates after 4 hours, using a record with working time of 09:00 to 17:00 on weekdays.
| Case created | Working time counted | Escalates |
|---|---|---|
| Tuesday 10:00 | Starts at once | Tuesday 14:00 |
| Tuesday 15:00 | 2 hours on Tuesday, then 2 hours on Wednesday | Wednesday 11:00 |
| Friday 16:00 | 1 hour on Friday, then 3 hours on Monday | Monday 12:00 |
| Saturday 11:00 | Clock starts when the next working period begins | Monday 13:00 |
If Monday were a holiday in the last two rows, Tuesday would replace it, because the holiday removes Monday's working time.
The diagram shows how Salesforce decides whether the clock is running.
Choosing business hours in an escalation rule
Business hours are chosen in two places in an escalation rule.
- Rule entry level. Each rule entry has a Business Hours setting. You can choose Use business hours specified on the case or Ignore business hours, or select Use the following business hours and name a record.
- Case level. A case has a Business Hours field. If a rule entry says to use the hours specified on the case, Salesforce reads that field.
Choosing the right option depends on the situation:
| Option | Behavior | Use when |
|---|---|---|
| Ignore business hours | Age counts continuously, including nights, weekends, and holidays | Severity 1 incidents or any promise measured in elapsed time |
| Use the following business hours | Age counts only inside a fixed record | One team handles every case that matches the entry |
| Use business hours specified on the case | The case's own field selects the record | Several regional teams share one rule |
If the case has no business hours value and the entry says to use the case's hours, Salesforce falls back to the org's default business hours. Check the default record. If it is wrong, many cases will escalate at unexpected times.
Setting business hours on a case
The Business Hours field on a case is filled in several ways. It takes the default record when a case is created, unless something else sets it. Typical alternatives are:
- An entitlement or entitlement process that sets business hours.
- A flow or Apex trigger that sets the field based on country, account tier, or queue.
- A user choosing a value manually, if the field is on the page layout.
The following Apex sets business hours on a case before insert by looking up a record by name:
BusinessHours bh = [
SELECT Id
FROM BusinessHours
WHERE Name = 'EMEA Support' AND IsActive = true
LIMIT 1
];
Case c = new Case(
Subject = 'Invoice question',
Origin = 'Email',
BusinessHoursId = bh.Id
);
insert c;Calculating working time in Apex
Apex has a BusinessHours class that applies the same logic as the platform. It helps you check what an escalation will do, or report on working time.
BusinessHours bh = [
SELECT Id
FROM BusinessHours
WHERE IsDefault = true
LIMIT 1
];
Datetime now = System.now();
Boolean working = BusinessHours.isWithin(bh.Id, now);
Datetime nextStart = BusinessHours.nextStartDate(bh.Id, now);
Datetime due = BusinessHours.add(bh.Id, now, 4 * 60 * 60 * 1000L);
System.debug('Within hours now: ' + working);
System.debug('Next working start: ' + nextStart);
System.debug('Four working hours from now: ' + due);The methods used here:
isWithin(id, time)returns true if the time falls inside working time and not on a holiday.nextStartDate(id, time)returns the next moment working time begins. If the time is already inside working time, it returns that time.add(id, startTime, milliseconds)adds working time to a start time.
The interval for add is in milliseconds, so four hours is 4 * 60 * 60 * 1000L. The L suffix makes it a Long, which the method requires.
Edge cases and common errors
- Wrong time zone. The time zone on the business hours record decides where the working day starts. It does not depend on the user's own time zone. A record set to Pacific time with hours 09:00 to 17:00 means 17:00 Pacific, even if the agent is in London.
- Missing holiday link. Creating a holiday does nothing until you link it to a business hours record.
- Past holidays. A one-time holiday in the past has no effect on current cases. A recurring holiday keeps applying.
- Inactive records. A rule entry that names an inactive record cannot use it. Check the active flag when escalation seems to ignore your hours.
- Default confusion. Cases created before you changed the default keep their stored value. Only new cases get the new default.
- Timing granularity. Escalation rules are evaluated on a schedule by Salesforce, roughly every 30 minutes. A rule set for 4 hours can fire some minutes late. Do not use it for tight time promises.
- Age is not reset by hours. The case's age runs from creation. Changing the business hours on a case does not restart the clock. It changes how elapsed time is counted.
- Edits are not retroactive for past events. Changing hours affects future evaluations. It does not undo an escalation that already ran.
Checking your setup
A short checklist helps before you write the escalation rule in the next chapter:
- Create one business hours record per distinct team schedule.
- Set the time zone to the zone of the team, not of the administrator.
- Link every relevant holiday, and mark recurring holidays as recurring.
- Confirm which record is the default.
- Decide whether the case's Business Hours field will be set by default, by automation, or by hand.
- Run the Apex checks above in Developer Console with sample timestamps, and compare with your expectations.
Exercise
A team's business hours record is 09:00 to 17:00 Monday to Friday. A rule entry escalates cases after 3 hours of working time using this record. A case is created on Thursday at 15:00. Friday is a linked all-day holiday. When does the case escalate?
Show answer
The case gets 2 working hours on Thursday (15:00 to 17:00). Friday is removed by the holiday, and Saturday and Sunday are non-working days. The remaining 1 hour is counted on Monday from 09:00, so the case escalates on Monday at 10:00 (subject to the delay of the scheduled escalation check).
Exercise
You run a Severity 1 queue with a promise to act within 2 hours at any time of day. Which business hours setting should the rule entry use, and why?
Show answer
Choose "Ignore business hours". The promise is measured in elapsed time, so nights, weekends, and holidays must count toward the 2 hours. Any business hours record would pause the clock outside working time and delay escalation.