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

Version 1 Next »

To build custom functionality on the template form, Booker25 allows you to bind an apex function to the change event of fields on the form.
To do this you have to create an apex class that implements System.callable and create a system setting with the name 'Template On Change Class' with a string value set to the name of the class.
This class is then expected to handle two different actions: getChangeHandlerInfo and onChange
The getChangeHandlerInfo action will be called when the form is initialized and should return Map<String, Map<String, Object>>. This specifies the fields that should have handlers and settings on how to run those handlers.
Example:
new Map<String, Map<String, Object>> {
    'Name' => new Map<String, Object> {
        'runBeforeBooker' => true
    }
}
The runBeforeBooker parameter specifies if the handler should run before or after any potential Booker25 handlers on the field.
The onChange action will be called when any of the fields specified in getChangeHandlerInfo are changed by the user. 
This method receives a few parameters through the parameter map.
template => The current reservation template object on the form. Type : B25__Reservation_Template__c
fieldName => The field name of the field that triggered the change event. Type : String
newValue => The current value of the field.
previousValue => The value of the field before it was changed.
This action should return a Map<String, Object> which you can populate with two optional keys template and  errorObject.
  • template is optional and should be of type B25__Reservation_Template__c and only contain the fields you want to update on the form. You can return the originally provided object but this will require more processing on the client and will override any fields changed by the user while the function ran. For these reasons it is advised to return a new B25__Reservation_Template__c object with only the fields you want to update on the form.
  • errorObject is optional and can either be a String or a more complex error object.
If you want to display a simple toast notification you can put a simple String in the errorObject key.
For more complex error handling you should return an object in the following shape.
{
    ok: false,
    body: {
        enhancedErrorType: 'RecordError'
        message: 'Toast Message Header',
        output: {
            errors: [{
                message: 'Toast error message text'
            }],
            fieldErrors: {
                'FieldName' : [{
                    field: 'FieldName'
                    message: 'error to show on field'
                }]
            }
        }
    }
}
  • No labels