Restocker Calendars

How do Restocker Calendars Work?

The Restocker App uses Calendar Anything to create and render Calendars.

In order for these Calendars to be displayed as part of record pages, we needed a framework for rendering them inside of another VF page that could be embedded in a Lightning Record Page.
To solve this we created a series of Visual Force pages for each Calendar:

- restockerCalendarRestockerView
- restockerCalendarManagerView
- restockerCalendarAccountServices
- restockerCalendarAccountAssets

Updating or Creating New Restocker Calendars

There are a couple of key parts to Restocker Calendars:

- the Calendar Anything Calendar
- the VisualForce Page
- the RestockerCalendarController
- a Restocker_Default_Settings__mdt field

Adding a Metadata Field

The first step in creating a new Calendar is to add a field to the Restocker_Default_Settings__mdt.
The field should be an 18 character String and follow the naming convention 'CalendarID_*CalendarName*' e.g. 'CalendarID_Example'.

Updating the RestockerCalendarController Class

In order to feed the VF page with the Calendar ID we will need to update the RestockerCalendarController class to fetch the ID from the metadata.

Add a variable to the Class with a getter that retrieves the field. e.g.

public String calendarIDExample { 
	get {
		return this.settings.CalendarID_Example__c;
	}
}
Click to copy

Add the field to the test settings in the RestockerCalendarControllerTest class and add an Assert.areEqual for the new variable.

The Visual Force Page

How do Restocker Calendar VF Pages Work?

Each page relies on the RestockerCalendarController Apex class which fetches the relevant CA Calendar ID from the Restocker_Default_Settings__mdt.default Metadata record.

The controller fetches the required Calendar ID and returns it to the page where we include the SLCA2 Calendar Anything VisualForce Component.
We set various parameters for the component during this step.

Creating a VF Page

The CA VF page should use RestockerCalendarController as the controller.

It will include the SLCA2 CA component.

The parameters for the component should at a minimum include the following:

urlparams="l_ds=0&hh=1&sb=2"
readonly="{
	edit : false, 
	create : false, 
	detail : true, 
	move : false, 
	hover : true, 
	contextEvent : false, 
	contextCalendar : false, 
	contextArea : false,
	cloneSharing : false
}"
userAdditionalSettings="{
	layoutTheme: 'lightning',
	size: 'middle',
	showTitles: 2,
	barLabelTime: 'start',
}"
Click to copy

Set the Calendar that will be displayed by including the following parameters. (Replace "calendarIDExample" with the variable from the RestockerCalendarController)

calendar="{!calendarIDAccountAsset}"
enabled="{!calendarIDAccountAsset}"
Click to copy

The Dynamic record ID filter can be set and enabled using the following. (Replace "calendarIDExample" with the variable from the RestockerCalendarController)

filter="{
	filtersPV : '{!recordId}',
	filtersApplyTo : '{!calendarIDAccountAsset}'
}"
Click to copy

Additional parameters and settings can be added, references for these are available in the CA documentation (note: reference the classic CA documentation, not the CA Lightning).

The Calendar Anything Calendar

The following steps must be taken into consideration while creating the Calendar Anything Calendar:

  1. Access - The settings on Restrict Visibility with Public Groups is the only way to grant access to a CA Calendar.
    In our case you may opt to use individual groups, but it is best to use 'All Users'. Access to the records themselves will still be controlled by Sharing Settings.
  2. Filter Criteria - In order to create filters that change based on the page the Calendar is shown on (e.g. the Asset Calendar is filtered based on the Asset record page where the Calendar is shown),
    the filter in 'Filter Criteria' must be 'Dynamic'. This is set by pressing the 'Dyn' button next to the filter in the CA setup.

Once the Calendar has been created and saved, take the ID from the Calendar and update the Restocker_Default_Settings__mdt.default record with the new ID.

Adding the VF page to a Lightning Record Page

The created VF page and Calendar can be embedding in a Lightning Record Page by adding the VisualForce component to the page in Lightning Page Builder and including the recordID as an input parameter.