Copy a field to all other reservations on the form

This article explains how to copy values over to other reservations, when you have multi-select enabled on your calendar.

Prerequisites

Event Handler

Implement the following event handler:

global class CopyField extends B25.FormEventHandler { private SObjectField fieldToCopy; global CopyField(SObjectField fieldToCopy) { this.fieldToCopy = fieldToCopy; } global override void handleEvent(B25.FormEvent event, B25.Form form) { B25.FormRecord activeRecord = form.getActiveRecord(); Object fieldValue = activeRecord.get(this.fieldToCopy); if (form.hasParentRecord()) { B25.FormRecord parentRecord = form.getParentRecord(); if (parentRecord != activeRecord) { parentRecord.put(this.fieldToCopy, fieldValue); } } if (form.hasChildRecords()) { for (B25.FormRecord childRecord : form.getChildRecords()) { if (childRecord != activeRecord) { childRecord.put(this.fieldToCopy, fieldValue); } } } } }

The handler code above is slightly more complex than strictly necessary for this example, using form.hasParentRecord() and form.hasChildRecords() to prevent errors in case this code runs on a calendar without multi-select enabled.

Customizer Class

Now add the following lines to the customize method inside your customizer class:

form.getField(B25__Reservation__c.B25__Title__c).onUpdate(new CopyField(B25__Reservation__c.B25__Title__c)); form.getField(B25__Reservation__c.B25__Account__c).onUpdate(new CopyField(B25__Reservation__c.B25__Account__c));

This adds the handlers to the Account and Title fields, which will listen for updates to those fields, and then copy those values over to the other reservations.

Test your solution

  1. Go to the calendar.

  2. Use multi-select to create multiple reservations.

  3. Give the reservation a title.

  4. Switch to other reservations using the sidebar of the form.

  5. Note that the titles all match.

  6. Now set an Account on any reservation.

  7. Switch to other reservations using the sidebar of the form.

  8. Note that the accounts all match.

Full code

global with sharing class CustomFormLogic implements B25.Form.Customizer { global void customize(B25.Form form) { form.getField(B25__Reservation__c.B25__Title__c).onUpdate(new CopyField(B25__Reservation__c.B25__Title__c)); form.getField(B25__Reservation__c.B25__Account__c).onUpdate(new CopyField(B25__Reservation__c.B25__Account__c)); } global class CopyField extends B25.FormEventHandler { private SObjectField fieldToCopy; global CopyField(SObjectField fieldToCopy) { this.fieldToCopy = fieldToCopy; } global override void handleEvent(B25.FormEvent event, B25.Form form) { B25.FormRecord activeRecord = form.getActiveRecord(); Object fieldValue = activeRecord.get(this.fieldToCopy); if (form.hasParentRecord()) { B25.FormRecord parentRecord = form.getParentRecord(); if (parentRecord != activeRecord) { parentRecord.put(this.fieldToCopy, fieldValue); } } if (form.hasChildRecords()) { for (B25.FormRecord childRecord : form.getChildRecords()) { if (childRecord != activeRecord) { childRecord.put(this.fieldToCopy, fieldValue); } } } } } }