Pre-Filtering in Salesforce
Adding Additional Criteria When Creating A Calendar
By default, Salesforce calendars in DayBack can be filtered by record type. However, you may want to add additional criteria to a calendar. For instance, a System Administrator might want a calendar that only shows their own events instead of everyone’s events allowed by their profile.
Using a Formula Field to Define an Event's Start Time
DayBack identifies Salesforce records by querying a date range specified by the user's current view. This query relies on the value of the Start
time configured in the calendar's field mapping. If the Start
variable is empty, DayBack will ignore that record. Using this logic, you can create a formula field that returns either a DateTime
or Date
value based on additional criteria, or returns a blank value for records that should be omitted. For example, the formula below can be used to represent the event's Start
time for events in the standard Salesforce Event object. This formula returns a valid DateTime
only if the event belongs to the current user:
if ( $User.Id = OwnerId , If( IsAllDayEvent , DATETIMEVALUE(ActivityDate) , ActivityDateTime ) , DATETIMEVALUE('') )
You can then map this formula field as the Start
field in DayBack’s field mapping for this calendar.
Handling Event Editing with a Formula Field
If the setup remains unchanged, users attempting to edit an event will encounter an error, as the formula field is not editable. However, DayBack allows us to transform edits using an On Event Save Custom Event Action. This action lets developers manipulate the changesObject .
With this object, we can remove properties that cannot be edited and add new ones. One of the nice features of the changesObject
is that it supports both the DayBack property names and the Salesforce field API names, even for fields that aren't mapped in DayBack. When a user attempts to edit the Start
formula field, this change can be removed from the changesObject
and replaced with a change that sets the date of the actual editable DateTime
field in Salesforce.
Below is an example of an On Event Save action that facilitates smooth editing by bypassing the non-editable formula field.
// Purpose: // Prevents the editing of the mapped start formula // field and instead edits the editable datetime // field that the formula is based on // // Event 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; }
With this action in place, users can edit events without encountering errors, as the necessary changes are redirected from the formula field to the appropriate editable field in Salesforce.