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

« Previous Version 17 Next »


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.

  3. Implement the call method to handle the getChangeHandlerInfo action.

  4. Implement the call method to handle the onChange action.

Implementing getChangeHandlerInfo

The getChangeHandlerInfo action will be called when the form is initialized and should return Map<String, Map<String, Object>>. This map specifies which fields will trigger the onChange action explained in the next section.


Example return value
return 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 the following parameters through the parameter map:

Parameter

Data type

Remarks

template 

B25__Reservation_Template__c

The current reservation template record on the form.

fieldName 

String

The API name of the field that triggered the change event.

newValue 

Object

The current value of the field.

previousValue 

Object

The value of the field before it was changed.

The method 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 can 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'
                }]
            }
        }
    }
}


On this page

  • No labels