Customize the Published Reservations
When publishing a template, actual reservations will be created. These reservations can be customized by implementing an Apex class. This article describes how to do this.
Create an Apex Class
Create a global Apex class that implements the Callable Interface.
Implement the
call
method inside your class.The
call
method is expected to return aB25__Reservation__c
which will be the blueprint for the generated reservations.
More details about this method can be found below in the section ‘Implementing the Call Method’.Save your class and remember the name for the next section.
Create a Custom Setting
Create a new Custom Setting of type
B25__System_Setting__c
.For the setting Name, fill in
Template Reservation Prototype Class
.For the String Value, fill in the name of the Apex class that you created in the previous section.
Save the setting. When publishing templates, your class will now be used.
Implementing the Call Method
The call
method will be called with the following arguments: call(String action, Map<String, Object> args)
.
action
will have the value 'getPrototypeForTemplate'
args
will contain two keys:
'template'
will contain theB25__Reservation_Template__c
being published'reservation'
will contain a prototypeB25__Reservation__c
which contains information about the start and end time
The call
method is expected to return a B25__Reservation__c
which will be the blueprint for the generated reservations.
Tip: you can simply modify the 'reservation'
being passed as input, and return it.
Code Example
global with sharing class MyCustomPublisher implements System.Callable {
public Object call(String action, Map<String, Object> args) {
// get the template and query additional fields
B25__Reservation_Template__c template = (B25__Reservation_Template__c) args.get('template');
template = [
SELECT B25__Staff__c, B25__Resource__c
FROM B25__Reservation_Template__c
WHERE Id = :template.Id
];
// get the reservation and modify it
B25__Reservation__c reservation = (B25__Reservation__c) args.get('reservation');
reservation.B25__Resource__c = template.B25__Resource__c;
reservation.B25__Staff__c = template.B25__Staff__c;
reservation.B25__Title__c = 'This reservation was created by MyCustomPublisher';
return reservation;
}
}