Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

Finds available time slots for a given reservation.

Methods

Expand
titlefindTimeSlots

Description

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

Signature

Code Block
global static B25.TimeSlotFinder.Result findTimeSlots(B25.TimeSlotFinder.Context)

Parameters

Code Block
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 Block
B25.TimeSlotFinder.Result

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

Expand
titlefindTimeSlotsBulkified

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 Block
global static List<B25.TimeSlotFinder.Result> findTimeSlotsBulkified(List<B25.TimeSlotFinder.Context> contexts)

Parameters

Code Block
List<B25.TimeSlotFinder.Context>

A list of request contexts.

Return Type

Code Block
B25.AvailableTimeRanges.Result

A list of results.

Inner Classes

Expand
titleContext

Description

This class wraps the request context.

Properties

Code Block
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 Block
Map<String, List<SObject>> junctions

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

Code Block
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 the TimeSlotGenerator documentation.

Expand
titleResult

Description

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

Properties

Code Block
List<B25.TimeSlot> timeSlots

The time slots when the given reservation (and junctions) are available. Each time slot has a startDateTime and endDateTime. For more details see the TimeSlot documentation.

Example

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

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);
}