...
For each dimension that a reservation can be related to (through either a lookup or a junction), this class supports two approachesuse cases:
Simple - The exact related record
...
is already known.
...
I.e. the resource lookup has already been populated with the id of room one.
Complex - The
...
related record
...
can be any out of a pool of records. I.e. we have a pool of resources (let’s say all rooms in building one), for which we want to know all the possible time slots
...
.
These use cases can be mixed in a single call to the method. For example the resource is fixed but the staff can be any from a pool of staff members.
Example use cases for lookups
...
Expand | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
DescriptionThis class wraps the request context. Properties
Contains the definition of what the resulting series of slots should look like, such as the date range, slot duration and slot interval. For more details see TimeSlotGenerator
The reservation to find available time slots for. Make sure all fields that can influence conflict checking are populated. If you are applying the simple use case for lookups (explained here), make sure any lookups to dimensions (resource/staff/etc) that need to be available are populated. Start and end times are not necessary and will be ignored.
Optional. If you are applying the complex use case for lookups (explained here), populate this with the possible ids mapped by the api name of the corresponding lookup field.
Optional. If you need any junctions to be available, add them here mapped by relationship name. Applies to both the simple and the complex use case.
Optional. If you are applying the the complex use case for junctions, populate this with the required numbers of available junctions, mapped by relationship name. |
Expand | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
DescriptionThis class wraps the result, which contains a list of available time slots. Properties
The time slots when the given reservation (and junctions) are available. Each time slot has a If you are applying the complex use case for at least one lookup or junction, this property will contain additional data. Each B25.TimeSlot entry in this list will be castable to B25.TimeSlotWithReservations, which have an additional property:
This property will contain all the reservations that are possible during that time slot. The B25.Reservation data type is a wrapper around a reservation and its child records. It has the following properties:
The actual reservation record.
The child records of the reservation (mapped by relationship name). This When applying the complex use case for junctions, this will contain the available junctions at the given time slot. |
Example
Simple use case
This example shows the simple use case (both for lookups and junctions).
Code Block |
---|
B25.TimeSlotFinder.Context context = new B25.TimeSlotFinder.Context();
// set the reservation to find time slots for
context.reservation = new B25__Reservation__c(
// make sure to populate all fields that are relevant for conflict checking
// and link this reservation to all dimensions that need to be available
B25__Resource__c = someResourceId
// note that start and end times are not necessary
);
// if you need any junctions to be available, map them by relationship name
context.junctions = new Map<String, List<SObject>>{
'B25__Reservation_Contacts__r' => new List<SObject>{
new B25__ReservationContact__c(
B25__Contact__c = someContactId
// note that a reservation id is not necessary
)
}
};
// the time slot context defines what the resulting series of slots should look like
context.timeSlotContext = new B25.TimeSlotGenerator.Context();
context.timeSlotContext.startOfRange = System.now();
context.timeSlotContext.endOfRange = System.now().addDays(7);
context.timeSlotContext.duration = 60;
context.timeSlotContext.interval = 15;
// call the method and do something with the result
B25.TimeSlotFinder.Result result = B25.TimeSlotFinder.findTimeSlots(context);
for (B25.TimeSlot timeSlot : result.timeSlots) {
System.debug('available time slot from ' + timeSlot.startDatetime
+ ' until ' + timeSlot.endDatetime);
} |
Complex use case
This example shows the complex use case for lookups:
Code Block |
---|
B25.TimeSlotFinder.Context context = new B25.TimeSlotFinder.Context(); // the time slot context defines what the resulting series of slots should look like context.timeSlotContext = new B25.TimeSlotGenerator.Context(); context.timeSlotContext.startOfRange = System.now(); context.timeSlotContext.endOfRange = System.now().addHours(2); context.timeSlotContext.duration = 60; context.timeSlotContext.interval = 15; // specify all the potential resource ids // NOTE: replace these with resource ids that exist in your org! context.fieldIds = new Map<String, List<Id>>{ 'B25__Resource__c' => new List<Id>{'a0eJX000000hnL7YAI', 'a0eJX000000hnL8YAI'} }; // call the method and do something with the result B25.TimeSlotFinder.Result result = B25.TimeSlotFinder.findTimeSlots(context); for (B25.TimeSlot timeSlot : result.timeSlots) { System.debug('available time slot from ' + timeSlot.startDatetime + ' until ' + timeSlot.endDatetime); B25.TimeSlotWithReservations timeSlotWithReservations = (B25.TimeSlotWithReservations) timeSlot; System.debug(timeSlotWithReservations.reservations); } |
GoMeddo Rest API
In the GoMeddo Rest API, there is a similar function called /timeSlots that displays available timeslots based on a given reservation.