How do Time Slots inside Operating Hours work when customers book Field Service appointments, and how do you create them in Apex?
Answer
Time Slots define when a territory is open for work. They are the building blocks of Operating Hours.
Structure
- Operating Hours: a named calendar with a time zone, such as "Jaipur Weekdays".
- Time Slot: one window inside it, with day of week, start time, end time and a type (Normal or Extended).
apex
OperatingHours oh = new OperatingHours(Name = 'Jaipur Weekdays', TimeZone = 'Asia/Kolkata');
insert oh;
insert new TimeSlot(
OperatingHoursId = oh.Id,
DayOfWeek = 'Monday',
StartTime = Time.newInstance(9, 0, 0, 0),
EndTime = Time.newInstance(17, 0, 0, 0),
Type = 'Normal'
);
For customer scheduling
- When a customer or agent asks for slots, the engine checks the territory's Operating Hours, then removes times when no qualified resource is free.
- The remaining times are offered as bookable slots or arrival windows.
Wrong time zones or missing slots are among the most common reasons no slots appear.
Time SlotsOperating HoursAppointment BookingApex