You are viewing an old version of this page. View the current version.
We have covered setting up simple Resource Titles to display fields of your resource records (or other dimensions) on the calendar. It is also possible to calculate dynamic values on the fly, using your own Apex logic.
For configuring simple Resource Titles, see: Show fields on calendar resources
One example use case for dynamic titles is summing values of reservations visible in the current view, as shown in the screenshot below:
Only use dynamic titles on the multi resource calendar when there is no other way to achieve the same functionality (by using a formula field for example).
The multi resource calendar could potentially display a large number of resources, and dynamically recalculating the values every time the users view changes can negatively impact the user experience. This is of less concern on the single resource calendar but other options are almost always faster.
Create an Apex class
Write a global apex class that implements the B25.Util_PluginManager.DynamicResourceTitles interface.
Add the following method: Map<Id, String> calculateResourceTitles(B25.Util_PluginManager.DynamicResourceTitleData dataObj);
See the Interface Reference section below for more details.
Save the class.
Create a Resource Title record
Activate your implementation on a calendar by creating a Resource Title record for it.
Go to the Calendars tab and find the calendar that you want to apply the dynamic titles on.
On the Related subtab, find the Resource Titles related list and click New.
Make sure to select Resource Title when prompted for the record type.
For the Title Name, enter the name of the class you created in the previous section.
Check the Dynamic checkbox.
The DynamicResourceTitles interface enforces one method: calculateResourceTitles. This method takes a B25.Util_PluginManager.DynamicResourceTitleData object as input. This object contains the following information:
The start of the current view that the user sees on the calendar.
The end of the current view that the user sees on the calendar.
Map of resource ids to a list of the ids of the reservations that are currently visible to the user. This list will also contain any unshared reservations that are visible to the user (if "Show greyed out blocks on the calendar for unshared reservations" is enabled). If you want to query the unshared reservations as well as the shared ones the implementation class needs to be without sharing.
Map of resource ids to a list of the ids of the reservations that are currently hidden from the user by reservation filters on the calendar.
Using this information the method should calculate the values for each resource and return a Map<Id, String> containing a mapping of the resource to the value that should be displayed on the calendar.
The following example displays the number of currently visible reservations in each resource.
Unit testing dynamic resource titles
To unit test your implementation you can construct a B25.Util_PluginManager.DynamicResourceTitleData set the parameters required by your implementation and call your calculateResourceTitles implementation.
- No labels