Skip to main content
Skip table of contents

TimeSlotFinder

Finds available time slots for a given reservation.

Methods

findTimeSlots
Description

This method returns the times that a given reservation (optionally with junctions) is possible.

Signature
CODE
global static B25.TimeSlotFinder.Result findTimeSlots(B25.TimeSlotFinder.Context)
Parameters
CODE
B25.TimeSlotFinder.Context

Contains the reservation, its junctions, and a definition of what the resulting series of time slots should look like (such as slot duration and interval ).

Return Type
CODE
B25.TimeSlotFinder.Result

Contains a List<B25.TimeSlot> timeSlots property with the available time slots.

findTimeSlotsBulkified
Description

Bulkified version of findTimeSlots. At the time of writing, this method is for convenience only and does not do anything more efficient than calling the unbulkified method multiple times.

Signature
CODE
global static List<B25.TimeSlotFinder.Result> findTimeSlotsBulkified(List<B25.TimeSlotFinder.Context> contexts)
Parameters
CODE
List<B25.TimeSlotFinder.Context>

A list of request contexts.

Return Type
CODE
B25.AvailableTimeRanges.Result

A list of results.

Inner Classes

Context
Description

This class wraps the request context.

Properties
CODE
B25__Reservation__c reservation

The reservation to find available time slots for. Make sure any lookups are populated to dimensions (resource/staff/etc) that need to be available, as well as any other fields that can influence conflict checking. Start and end times are not necessary.

CODE
Map<String, List<SObject>> junctions

Optional. If you need any junctions to be available, add them here mapped by relationship name.

CODE
B25.TimeSlotGenerator.Context timeSlotContext

Contains the definition of what the resulting series of slots should look like, such as slot duration and interval. For more details see TimeSlotGenerator.

Result
Description

This class wraps the result, which contains a list of available time slots.

Properties
CODE
List<B25.TimeSlot> timeSlots

The time slots when the given reservation (and junctions) are available. Each time slot has a startDateTime and endDateTime.

Example

This example shows how you can use the class in your own code.

CODE
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);
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.