Pre-Filtering in Salesforce

Adding Additional Criteria To Your Calendars

By default, Salesforce calendars in DayBack can be filtered record type. But what if you want to add additional criteria to a calendar? For example, a System Administrator would like a calendar that just shows their own events instead of everybody's events allowed by their profile.

A formula field for the start

DayBack requires a value in the field mapped to the event start in order to find it in Salesforce, so if the value is empty, then DayBack will ignore that record. Using this logic, a formula field can be created that returns either a DateTime or Date value depending on some additional criteria. The formula below could be used in the Standard Event object and will just return a valid DateTime if it belongs to the current user.

	if ( $User.Id = OwnerId , If( IsAllDayEvent , DATETIMEVALUE(ActivityDate) , ActivityDateTime ) , DATETIMEVALUE('') )

The formula field can then be mapped as the Start field in DayBack's field mapping for this calendar.

What about editing?

If this set-up is left as is and a user attempts to edit an event, then they'll get an error that the formula field is not editable, which would be expected. Fortunately, DayBack provides us with a way to transform the edit and modify it for our own purposes. This is done with an On Event Save Custom Event Action. Within the scope of an On Event Save action developers have access to the changesObject. With this object, we can remove properties that will be edited and add our own. One of the nice features here is that the changesObject will support both the DayBack property names and the Salesforce field API names so even fields that aren't mapped in DayBack can be edited. Below is an example of an On Event Save action that can be used in conjunction with the above formula field for smooth editing.

//Purpose: 
//Prevents the editing of the mapped start formula field and instead edits the editable datetime field the formula is based on

//Action Type: On Event Save 
//Prevent Default Action: No
 
//More info on On Event Save actions and objects here: 
//https://docs.dayback.com/article/20-event-actions

//detect if the start has been editied
if(changesObject.start) {
	//copy the attempted edit to Salesforce's editable DateTime field
  	changesObject.StartDateTime = changesObject.start.format();
	//remove the edit to start as it's mapped to the formula field
  	delete changesObject.start;
}

Still need help? Message Us Message Us