Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

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

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

Parameters

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

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

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

Parameters

List<B25.TimeSlotFinder.Context>

A list of request contexts.

Return Type

B25.AvailableTimeRanges.Result

A list of results.

Inner Classes

 Context

Description

This class wraps the request context.

Properties

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.

Map<String, List<SObject>> junctions

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

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

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.

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);
}
  • No labels