You can add your own custom buttons to the Reservation form on the calendar. These buttons can reference a VisualForce page and its controller to perform any kind of logic on existing Reservations.
You can also define a custom Apex class to perform actions on the Reservation without leaving the Reservation Form.
Redirecting to a custom VisualForce page
For the sake of this tutorial, we will assume that you have already created the VisualForce page that will perform logic on the reservation
Click on Setup and search for Custom Settings
Click on Manage next to Custom Buttons
Click New
Fill in an appropriate Name and Label
Fill in /apex/c__{vfpagename}?id= in the URL field where {vfpagename} is the name of your visualforce page
Click Save
This button will now be added to the reservation form. On click, it will perform the logic in the VisualForce page's controller on the reservation record.
Defining a custom apex class
For the sake of this tutorial, we will assume that you have already created the VisualForce page that will perform logic on the reservation
Create a global Apex class that implements the B25.ExecutableCustomButton interface. For an example, see the code below.
Click on Setup and search for Custom Settings
Click on Manage next to Custom Buttons
Click New
Fill in an appropriate Name and Label
Fill in the name of the apex class in the Executable Class Name field
Click Save
This button will now be added to the Reservation Form. On click, it will perform the logic in the Apex class and update the form according to any changes made.
Users will only see the button if they have access to the specified Apex class
Implementing the B25.ExecutableCustomButton interface
The SObjects passed to this method are the SObjects used to render the form and save the data to the database. Any changes made to the objects are propagated to the Reservation Form. If any errors are thrown in the implementation on update, they are shown to the user as a page message. However a failed update does not update the Reservation Form back to its original values, that is the responsibility of the implementation.
The B25.ExecutableCustomButton requires you to implement one method public void execute(B25.ExecutableCustomButtonContext context).
This method is called when the user clicks the button on the Reservation Form.
The ExecutableCustomButtonContext object contains the following data:
Name
Type
Description
reservation
B25__Reservation__c
The Reservation open on the Reservation Form
isRecurring
Boolean
If the Reservation is recurring
recurringReservation
B25__Recurring_Reservation__c
The Recurring Reservation object that belongs to the recurring series of this Reservation, if the Reservation is recurring
dimensionJunctions
Map<String, List<SObject>>
A map of any Dimension Junction objects. Mapped by the API name of the Dimension Junction Object
serviceReservations
List<B25__Service_Reservation__c>
The ServiceReservation currently on the form
Below is a sample implementation that moves the Reservation forward by one hour. It updates both the B25__StartLocal__c and B25__Start__c fields, as otherwise a 'time mismatch error' may occur.
Sample implementation
global with sharing class SampleImplementation implements B25.ExecutableCustomButton {
public void execute(B25.ExecutableCustomButtonContext context) {
context.reservation.B25__StartLocal__c = context.reservation.B25__StartLocal__c.addHours(1);
context.reservation.B25__EndLocal__c = context.reservation.B25__EndLocal__c.addHours(1);
context.reservation.B25__Start__c = context.reservation.B25__Start__c.addHours(1);
context.reservation.B25__End__c = context.reservation.B25__End__c.addHours(1);
Database.update(context.reservation);
}
}