Skip to main content
Skip table of contents

B25.Form

Overview

This class lets you inspect the current form state as well as perform actions on it, such as adding handlers or updating values.

The B25.Form class is the main point of interaction for anything that you want to do on the form. Inside the customize method (defined in the B25.Form.Customizer interface) you can add your own event handlers to the form (or its child elements). Inside the handleEvent method of your own handlers, you can inspect the current form state and update values on it (or its child elements). Use the getter methods to access lower level child elements, such as fields or related lists.

There are three events that you can hook into at the form level:

  • onInit - for prepopulating fields when a new reservation is created

  • onOpen - for changing the appearance of the form depending on the reservation being shown

  • onBeforeSave - for adding your own validation

Example 1: Adding a handler

Adding handlers is done inside the customize method of your own implementation of the B25.Form.Customizer interface.

Also see: Quick Start Guide

CODE
global with sharing class MyFormCustomizer implements B25.Form.Customizer {
    global void customize(B25.Form form) {
        form.getField(B25__Reservation__c.B25__Status__c).onUpdate(new MyStatusHandler());
    }
}

Example 2: Updating the form

Updating the form’s record is done using getActiveRecord() inside the handleEvent method of your own event handlers.

Also see: B25.FormEventHandler

CODE
global with sharing class MyStatusHandler extends B25.FormEventHandler {
    global override void handleEvent(B25.FormEvent event, B25.Form form) {
        form.getActiveRecord().put(B25__Reservation__c.B25__Title__c, 'Hello World!');
    }
}

Interfaces

B25.Form.Customizer

The B25.Form.Customizer interface is what you need to implement to attach your own handlers to the form (also see: Quick Start Guide). It only has one method, with the following signature:

CODE
void customize(B25.Form form)

Parameters:

Name

Type

Description

form

B25.Form

The form, to which you can add your own handlers.


Methods

getField

CODE
B25.FormField getField(SObjectField fieldToken)

This method will return a Field object for the specified SObjectField. The SObjectField must be an existing reservation field. You can use this Field object to bind handlers inside your Customizer class.

Return value:B25.FormField

Parameters:

Name

Type

Description

fieldToken

SObjectField

The token representing the field for which you want to get a FormField instance.

Example:

CODE
B25.FormField titleField = form.getField(B25__Reservation__c.B25__Title__c);
titleField.onUpdate(new MyCustomTitleFieldHandler()); // binds a handler to fire whenever this field changes

getActiveRecord()

CODE
B25.FormRecord getActiveRecord()

This method returns a wrapper representing the record that is currently visible on the form.

A form can have multiple records, for example when ‘Multi Select’ has been enabled on the calendar. This method will always return the record currently being viewed or edited.

Return value: B25.FormRecord

Example:

Update the reservation title from inside a B25.FormEventHandler

CODE
B25.FormRecord record = form.getActiveRecord();
record.put(B25__Reservation__c.B25__Title__c, 'Hello World');

getParentRecord()

CODE
B25.FormRecord getParentRecord()

This method returns a wrapper representing the parent record of the form, if it has any.

Return value: B25.FormRecord


hasParentRecord()

CODE
Boolean hasParentRecord()

Returns true if the form has a parent record.


getChildRecords()

CODE
B25.FormRecordCollection getChildRecords()

This method returns a wrapper representing all the child records of the form, if it has any.

Return value: B25.FormRecordCollection


hasChildRecords()

CODE
Boolean hasChildRecords()

Returns true if the form has a child records.


getButton

CODE
B25.FormButton getButton(String buttonName)

This method will return a Button object. The buttonName must be an existing button.

Return value: B25.FormButton

Parameters:

Name

Type

Description

buttonName

String

The name of the button to interact with.

Example:

CODE
B25.FormButton button = form.getButton('my-custom-button');

getSection

CODE
B25.FormSection getSection(String sectionName)

This method will return a Section object. The sectionName must be an existing section label.

Return value:B25.FormSection

Parameters:

Name

Type

Description

sectionName

String

The label of the section to interact with.

Example:

CODE
B25.FormSection section = form.getSection('Pricing');

getLookup

CODE
B25.Lookup getLookup(SObjectField fieldToken)

Similar to getField, but instead this method will return a Lookup object for the specified SObjectField. The SObjectField must be an existing lookup field on reservation.

Return value:B25.Lookup

Parameters:

Name

Type

Description

fieldToken

SObjectField

The token representing the lookup for which you want to get a FormField instance.

Example:

CODE
B25.Lookup resourceLookup = form.getLookup(B25__Reservation__c.B25__Resource__c);

getRelatedList

CODE
B25.RelatedList getRelatedList(SObjectType sObjectToken)

Returns the related list associated with the passed SObjectType token. The SObjectType must be a child of the form’s SObjectType (which is currently always B25__Reservation__c).

Return value:B25.RelatedList

Parameters:

Name

Type

Description

sObjectToken

SObjectType

The token representing the child object type for which you want to get a RelatedList instance.

Example:

CODE
B25.RelatedList contactList = form.getRelatedList(B25__ReservationContact__c.SObjectType);

getReservation

CODE
B25__Reservation__c getReservation()

Returns the actual reservation record of this form. You can use this method inside your handlers to get more information about the field values of the current reservation record.

Setting values directly on this record has no effect. If you want to update field values, call getField followed by updateValue instead, as illustrated below:

CODE
// to update a field inside a handler, instead of doing this:
form.getReservation().B25__Title__c = 'my title';
// you should do this:
form.getField(B25__Reservation__c.B25__Title__c).updateValue('my title');

Return value: B25__Reservation__c


onInit (without parameters)

CODE
List<B25.FormEventHandler> onInit()

Returns the list of handlers that have been defined to trigger when the form is initialized. For more details, see onInit (with parameter) below.

Return value: List<B25.FormEventHandler>


onInit (with parameter)

CODE
void onInit(B25.FormEventHandler handler)

This method adds a handler which triggers when the reservation form is initialized for a new reservation. It also triggers for each reservation that gets added to the sidebar of the form, such as for recurring reservations or when using custom form logic to add child reservations.

Adding an onInit handler is primarily intended to prepopulate fields on new reservations. For changing the appearance of the form, use an onOpen handler instead.

This method is intended to be used in the customize method defined in your implementation of the B25.Form.Customizable interface. Using it anywhere else, such as inside one of your event handlers, will not have any effect.

Parameters:

Name

Type

Description

handler

B25.FormEventHandler

The handler to trigger when the form is initialized.


onOpen (without parameters)

CODE
List<B25.FormEventHandler> onOpen()

Returns the list of handlers that have been defined to trigger when the form is opened. For more details, see onOpen (with parameter) below.

Return value: List<B25.FormEventHandler>


onOpen (with parameter)

CODE
void onOpen(B25.FormEventHandler handler)

This method adds a handler which triggers when the reservation form is opened for either a new or existing reservation. It also triggers when you switch to another reservation in the sidebar, which is visible if the form is showing multiple reservations, such as for recurring reservations or when using the multi-select mode on the calendar.

Adding an onOpen handler is primarily intended to change the appearance of the form depending on the reservation being shown. You can use this to show/hide fields, buttons, sections, etc. To prepopulate fields for new reservations, use an onInit handler instead.

This method is intended to be used in the customize method defined in your implementation of the B25.Form.Customizable interface. Using it anywhere else, such as inside one of your event handlers, will not have any effect.

Parameters:

Name

Type

Description

handler

B25.FormEventHandler

The handler to trigger when the form is opened.


onBeforeSave (without parameters)

CODE
List<B25.FormEventHandler> onBeforeSave()

Returns the list of handlers that have been defined to trigger when the form is opened. For more details, see onBeforeSave (with parameter) below.

Return value: List<B25.FormEventHandler>


onBeforeSave (with parameter)

CODE
void onBeforeSave(B25.FormEventHandler handler)

This method adds a handler which triggers when the reservation form is saved, but before the actual saving logic is executed. You can use such a handler to add your own validation, and show error toast messages for example (see showErrorToast below).

This method is intended to be used in the customize method defined in your implementation of the B25.Form.Customizable interface. Using it anywhere else, such as inside one of your event handlers, will not have any effect.

Parameters:

Name

Type

Description

handler

B25.FormEventHandler

The handler to trigger when the form is saved (before performing the actual save logic).


addButton

CODE
void addButton(B25.FormButton button)

Adds a button to the form. Must be called inside the customize method.

Parameters:

Name

Type

Description

button

B25.FormButton

The button to be added to the form.

Example:

CODE
form.addButton(new B25.FormButton('my-name', 'My Label'));

showSuccessToast

CODE
ToastNotification showSuccessToast(String title, String message)

Shows a success toast notification on the form.

Parameters:

Name

Type

Description

title

String

The title to be displayed on the toast notification.

message

String

The message to be displayed on the toast notification.

Example:

CODE
form.showSuccessToast('Success!', 'Changes saved succesfully.');

showErrorToast

CODE
ToastNotification showErrorToast(String title, String message)

Shows an error toast notification on the form.

Parameters:

Name

Type

Description

title

String

The title to be displayed on the toast notification.

message

String

The message to be displayed on the toast notification.

Example:

CODE
form.showErrorToast('Error', 'Something went wrong.');

showWarningToast

CODE
ToastNotification showWarningToast(String title, String message)

Shows a warning toast notification on the form.

Parameters:

Name

Type

Description

title

String

The title to be displayed on the toast notification.

message

String

The message to be displayed on the toast notification.

Example:

CODE
form.showWarningToast('Warning', 'Saving this record would result in a conflict.');

showInfoToast

CODE
ToastNotification showInfoToast(String title, String message)

Shows an info toast notification on the form.

Parameters:

Name

Type

Description

title

String

The title to be displayed on the toast notification.

message

String

The message to be displayed on the toast notification.

Example:

CODE
form.showInfoToast('Did you know?', 'In order to maintain air-speed velocity, a swallow needs to beat its wings forty-three times every second.');

JavaScript errors detected

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

If this problem persists, please contact our support.