B25.Form

Overview

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.

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: https://gen25-jira.atlassian.net/wiki/spaces/BPD/pages/1829372013

1 2 3 4 5 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 is done inside the handleEvent method of your own event handlers.

Also see: https://gen25-jira.atlassian.net/wiki/spaces/BPD/pages/1875116052

1 2 3 4 5 global with sharing class MyStatusHandler extends B25.FormEventHandler { global override void handleEvent(B25.FormEvent event, B25.Form form) { form.getField(B25__Reservation__c.B25__Title__c).updateValue('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: https://gen25-jira.atlassian.net/wiki/spaces/BPD/pages/1829372013). It only has one method, with the following signature:

1 void customize(B25.Form form)

Parameters:

Name

Type

Description

form

B25.Form

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


Methods

getField

1 B25.FormField getField(SObjectField fieldToken)

This method will return a Field object for the specified SObjectField. The SObjectField must be an existing reservation field.

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:

1 B25.FormField titleField = form.getField(B25__Reservation__c.B25__Title__c);

getLookup

1 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:

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

getRelatedList

1 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:

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

getReservation

1 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:

1 2 3 4 // 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)

1 List<B25.FormEventHandler> onInit()

Returns a reference to the list of handlers that have been defined to trigger when the form is initialized. You can use such a handler to prepopulate fields on the form, for example. If you simply want to set a single handler, you can use the onInit (with parameter) method described in the next section.

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.

Because this method returns a reference to the actual list (and not a copy), any changes you make to this list will directly affect the defined handlers.

Return value: List<B25.FormEventHandler>


onInit (with parameter)

1 void onInit(B25.FormEventHandler handler)

This method is a convenience method, and is identical to calling onInit().add(B25.FormEventHandler handler). See the previous section onInit (without parameters) for more details.

Parameters:

Name

Type

Description

handler

B25.FormEventHandler

The handler to trigger when the form is initialized.


onBeforeSave (without parameters)

1 List<B25.FormEventHandler> onBeforeSave()

Returns a reference to the list of handlers that have been defined to trigger when the form is saved, but before the actual saving logic is executed. You can use such a handler to add your own validation, for example. If you simply want to set a single handler, you can use the onBeforeSave (with parameter) method described in the next section.

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.

Because this method returns a reference to the actual list (and not a copy), any changes you make to this list will directly affect the defined handlers.

Return value: List<B25.FormEventHandler>


onBeforeSave (with parameter)

1 void onBeforeSave(B25.FormEventHandler handler)

This method is a convenience method, and is identical to calling onBeforeSave().add(B25.FormEventHandler handler). See the previous section onBeforeSave (without parameters) for more details.

Parameters:

Name

Type

Description

handler

B25.FormEventHandler

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


addButton

1 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:

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