AvailableTimeRanges

The AvailableTimeRanges class enables developers to generate a list of timeranges for when a specific dimension scope is available. This method does not only inspect Availbility records, but also existing Reservations that might block a dimension from being booked. It is useful for answering questions like: ‘When can this room be booked?’ or ‘Given these Staff members, who is available when?’. When used for Resources, you can include Services that must be available for the booking.

Methods

Description

This method takes a dimension scope, a date range, and a prototype Reservation. It will return a list of available time ranges mapped by date and dimension.

Signature

1 global static B25.AvailableTimeRanges.Result getTimeRanges(B25.AvailableTimeRanges.Context context)

Parameters

1 B25.AvailableTimeRanges.Context

An instance of B25.AvailableTimeRanges.Context. This class wraps the input parameters, such as the dimension scope, a date range, and a prototype Reservation.

Return Type

1 B25.AvailableTimeRanges.Result

An instance of B25.AvailableTimeRanges.Result. This contains a list of available time ranges mapped by date and dimension.

Inner Classes

Description

This class wraps the input parameters, such as the dimension scope, a date range, and a prototype Reservation.

Properties

1 Date startDate

The start of the date range that you are interested in. The result will not include available time ranges before this date. For performance reasons, try to keep the date range narrow.

1 Date endDate

The end of the date range that you are interested in. This date is exclusive. The result will not include available time ranges on or after this date. For performance reasons, try to keep the date range narrow.

 

1 String dimensionName

The name of the Dimension that you are interested in. A Dimension is an SObject that Reservations are related to. For example ‘B25__Resource__c’ or ‘B25__Staff__c’.

 

1 String dimensionFieldName

The name of the DimensionField that you are interested in. A DimensionField is a lookup from Reservation to a Dimension. For example ‘B25__Resource__c’ or ‘B25__Staff__c’.

 

1 Set<Id> dimensionIds

The collection of dimension record ids that you are interested in. For performance reasons, try to keep the size of this collection small.

 

1 B25__Reservation__c prototypeReservation

(Optional) If you have conflict checking configuration that depends on certain Reservation fields, you can include the prototypeReservation property with the required fields populated. An example could be that your configuration depends on B25__Quantity__c or B25__Status__r.B25__AllowDoubleBooking__c.

 

1 List<B25__Service_Reservation__c> serviceReservations

(Optional) If you include this property, the results will only include Resources where these Services are available with enough capacity. This property is only valid if your Dimension and Dimension Field are both set to ‘B25__Resource__c’.

 

Description

This class wraps the result, which contains a list of available time ranges mapped by date and dimension.

Properties

1 Map<Id, Map<Date, List<B25.AvailableTimeRanges.TimeRange>>> timeRanges

A list of time ranges, mapped by date, mapped by dimension id. The outer map will contain a key corresponding to each dimension id that was passed to the method in the dimensionIds property. The inner maps will contain a date key for each date in the date range (which were passed to the method in the startDate and endDate properties). The lists inside the inner maps will contain all the time ranges that the dimension is available on that date. If this list is empty, it means that the dimension is not available on that date.

 

Description

This class represents an available time range.

Properties

1 Time startTime

The time at which the dimension starts being available.

1 Time endTime

The time at which the dimension stops being available.

If startTime and endTime are both 0:00, this means that the dimension is available for the entire day.

Example for Lightning Flow

This code snippet shows how to make the method available for Lightning Flow:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 public class TimeRangeSelector { @InvocableMethod(label='Get available time range for single day' description='Returns a result object containing start and end time for the first available time range for the given Dimension Id' category='Scheduling') public static List<TimeRangeResult> getTimeRangeForSingleDay(List<TimeRangeSelector.TimeRangeRequest> requests) { List<TimeRangeResult> allResults = new List<TimeRangeResult>(); for (TimeRangeRequest request : requests) { allResults.add(TimeRangeSelector.getResultForRequest(request)); } return allResults; } private static TimeRangeResult getResultForRequest(TimeRangeRequest request) { B25.AvailableTimeRanges.Context context = TimeRangeSelector.createContext(request); B25.AvailableTimeRanges.Result result = B25.AvailableTimeRanges.getTimeRanges(context); Map<Date, List<B25.AvailableTimeRanges.TimeRange>> timeRangesForDimension = result.timeRanges.get(request.dimensionId); if (timeRangesForDimension != null) { List<B25.AvailableTimeRanges.TimeRange> timeRanges = timeRangesForDimension.get(request.inputDate); if (timeRanges != null && !timeRanges.isEmpty()) { B25.AvailableTimeRanges.TimeRange timeRange = timeRanges[0]; TimeRangeResult timeRangeResult = new TimeRangeResult(); timeRangeResult.startTime = timeRange.startTime; timeRangeResult.endTime = timeRange.endTime; return timeRangeResult; } } return null; } public class TimeRangeResult { @InvocableVariable(Label='Start Time') public Time startTime; @InvocableVariable(Label='End Time') public Time endTime; } public class TimeRangeRequest { @InvocableVariable(Label='Dimension Name' Required=true) public String dimensionName; @InvocableVariable(Label='Dimension Field Name' Required=true) public String dimensionFieldName; @InvocableVariable(Label='Dimension Id' Required=true) public Id dimensionId; @InvocableVariable(Label='Date' Required=true) public Date inputDate; } public static B25.AvailableTimeRanges.Context createContext(TimeRangeRequest timeRangeRequest) { B25.AvailableTimeRanges.Context context = new B25.AvailableTimeRanges.Context(); context.dimensionName = timeRangeRequest.dimensionName; context.dimensionFieldName = timeRangeRequest.dimensionFieldName; context.dimensionIds = new Set<Id>{timeRangeRequest.dimensionId}; context.startDate = timeRangeRequest.inputDate; context.endDate = timeRangeRequest.inputDate.addDays(1); return context; } }