Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

...

Booker25 allows you to define an interface which you can use to add your own custom logic whenever the Reservation Template being edited changes. You can use this to update dependent fields or display validation errors, for example.
To add your own logic on Template editing:
  1. Create a global class that implements the Callable interface (see https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_System_Callable.htm)
  2. Create a Custom Setting (of type B25 System Setting) with name 'Template On Change Class' and as value the name of the class you created in step 1.
The created class is then expected to handle two different actions: getChangeHandlerInfo and onChange.

Implementing getChangeHandlerInfo

The getChangeHandlerInfo action will be called when the form is initialized and should return Map<String, Map<String, Object>>. This map specifies

...

Example:

...

which fields will trigger the onChange action explained in the next section.


Code Block
titleExample return value
new Map<String, Map<String, Object>> {
    'Name' => new Map<String, Object> {
        'runBeforeBooker' => true
    },
	'B25__Start_Date__c' => new Map<String, Object> {
        'runBeforeBooker' => false
    },
}
The runBeforeBooker parameter specifies if the handler should run before or after any potential Booker25

...

handlers on the field. For most fields the value does not matter. The only fields for which it does matter are: 'B25__Start_Date__c', 'B25__End_Date__c', 'B25__Number_Of_Sessions__c', 'B25__Week_Offset__c', and 'B25__Day_Of_Week_Offset__c'. This is because Booker25 adds some logic to keep these fields consistent with each other. The runBeforeBooker parameter gives you control over whether your logic is executed before or after that.

Implementing onChange

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'
                }]
            }
        }
    }
}