B25.FormButton
Overview
Represents a button on the form.
Buttons allow you to fire your own custom logic by defining a B25.FormEventHandler for them. You can add buttons inside your B25.Form.Customizer using the B25.Form.addButton method.
Example Customizer
global with sharing class MyFormCustomizer implements B25.Form.Customizer {
global void customize(B25.Form form) {
form.addButton(new B25.FormButton('say-hello', 'Say Hello!')
.setClickHandler(new MyButtonHandler())
);
}
}
Example Handler
global with sharing class MyButtonHandler extends B25.FormEventHandler {
global override void handleEvent(B25.FormEvent event, B25.Form form) {
form.getField(B25__Reservation__c.B25__Title__c).updateValue('Hello World!');
}
}
Example Result
Constructors
FormButton(name, label)
global B25.FormButton(String name, String label)
Creates a new FormButton with the given name and label. The name should be a unique value and is used internally to recognize the button. The label is the text on the button that is displayed to the user.
Parameters:
Name | Type | Description |
---|---|---|
name | String | A unique name for the button, not displayed to the user. |
label | String | The text on the button, displayed to the user. |
Methods
setClickHandler
B25.FormButton setClickHandler(B25.FormEventHandler handler)
Sets a B25.FormEventHandler to fire when this button is clicked.
Return value: B25.FormButton
Parameters:
Name | Type | Description |
---|---|---|
handler | B25.FormEventHandler | The handler to be fired when the button is clicked. |
setFlowName
B25.FormButton setFlowName(String flowName)
Sets the name of the flow which will be triggered when the button is clicked. The event handler passes the current record to the specified flow and expects an updated version of the current record from the flow. A compatible flow for the event handler can be created using the Default Reservation Flow Template.
Return value: B25.FormButton
Parameters:
Name | Type | Description |
---|---|---|
flowName | String | The name of the flow to be triggered. |
setHideOnNewRecords
B25.FormButton setHideOnNewRecords(Boolean value)
If this property is set to ‘true’, the button will not be visible on new records (so only on existing records). The default value is ‘false’.
Return value: B25.FormButton
Parameters:
Name | Type | Description |
---|---|---|
value | Boolean | The value that you want to set the property to. |
setHideOnExistingRecords
B25.FormButton setHideOnExistingRecords(Boolean value)
If this property is set to ‘true’, the button will not be visible on existing records (so only on new record). The default value is ‘false’.
Return value: B25.FormButton
Parameters:
Name | Type | Description |
---|---|---|
value | Boolean | The value that you want to set the property to. |
setHideWhenEditing
B25.FormButton setHideWhenEditing(Boolean value)
If this property is set to ‘true’, the button will not be visible when editing a record (so only when viewing a record). The default value is ‘false’.
Return value: B25.FormButton
Parameters:
Name | Type | Description |
---|---|---|
value | Boolean | The value that you want to set the property to. |
setHideWhenViewing
B25.FormButton setHideWhenViewing(Boolean value)
If this property is set to ‘true’, the button will not be visible when viewing a record (so only when editing a record). The default value is ‘false’.
Return value: B25.FormButton
Parameters:
Name | Type | Description |
---|---|---|
value | Boolean | The value that you want to set the property to. |
setClosesForm
B25.FormButton setClosesForm(Boolean value)
If this property is set to ‘true’, form will be closed when the button is clicked. The default value is ‘false’.
Return value: B25.FormButton
Parameters:
Name | Type | Description |
---|---|---|
value | Boolean | The value that you want to set the property to. |
setConfirmationHeader
B25.FormButton setConfirmationHeader(String value)
If this property is set, the button will display a confirmation dialog when the button is clicked, prompting the user to confirm before the button action is executed. This property controls the dialog header text. This property is not set by default.
Return value: B25.FormButton
Parameters:
Name | Type | Description |
---|---|---|
value | String | The header of the confirmation dialog to display. |
setConfirmationBody
B25.FormButton setConfirmationBody(String value)
If this property is set, the button will display a confirmation dialog when the button is clicked, prompting the user to confirm before the button action is executed. This property controls the dialog body text. This property is not set by default.
Return value: B25.FormButton
Parameters:
Name | Type | Description |
---|---|---|
value | String | The body of the confirmation dialog to display. |
setConfirmationButtonLabel
B25.FormButton setConfirmationButtonLabel(String value)
If this property is set, the button will display a confirmation dialog when the button is clicked, prompting the user to confirm before the button action is executed. This property controls the confirmation button label text. This property is not set by default.
Return value: B25.FormButton
Parameters:
Name | Type |
---|---|
value | String |
hide
void hide()
Hides the button on the reservation form. Can be called from inside another handler, for example to hide buttons when the user selects a specific reservation type.
show
void show()
Makes the button visible again if it was hidden. Can be called from inside another handler, for example to show previously hidden buttons when the user selects a specific reservation type.
Example
global with sharing class MyFormLogic implements B25.Form.Customizer {
global void customize(B25.Form form) {
// add our own custom button
form.addButton(new B25.FormButton('my-custom-button', 'My Button Label'));
// trigger when the Reservation Type changes
form.getField(B25__Reservation__c.B25__Reservation_Type__c).onUpdate(new MyReservationTypeHandler());
}
global with sharing class MyReservationTypeHandler extends B25.FormEventHandler {
global override void handleEvent(B25.FormEvent event, B25.Form form) {
Id newReservationTypeId = (Id) event.getNewValue();
B25__Reservation_Type__c reservationType = [SELECT Name FROM B25__Reservation_Type__c WHERE Id = :newReservationTypeId];
if (reservationType.Name == 'Super Special Type') {
form.getButton('my-custom-button').hide();
} else {
form.getButton('my-custom-button').show();
}
}
}
}