Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Quick and Dirty Code Samples

...

Expand
titleIf the status of the reservation is "completed" hide the title field, otherwise show
Code Block
languagejava
global with sharing class MyFormLogic implements B25.Form.Customizer {
    global void customize(B25.Form form) {
        // This is where we will add our handlers to the form
        form.getField(B25__Reservation__c.B25__Status__c).onUpdate(new MyStatusHandler());
    }

    global with sharing class MyStatusHandler extends B25.FormEventHandler {
        global override void handleEvent(B25.FormEvent event, B25.Form form) {
            Id newStatusId = (Id) event.getNewValue();
            B25__Reservation_Status__c status = [
                SELECT Name
                FROM B25__Reservation_Status__c
                WHERE Id = :newStatusId
            ];

            if (status.Name == 'Completed') {
                form.getField(B25__Reservation__c.B25__Title__c).hide();
            } else {
                form.getField(B25__Reservation__c.B25__Title__c).show();
            }
        }
    }
}
Expand
titleCopy the title to all other reservations on the form

For this example you need to have multi-selection enabled on the Calendar, so the form can display multiple reservations.

Code Block
global with sharing class DefaultForm implements B25.Form.Customizer {

	global void customize(Form form) {
		form.getField(B25__Reservation__c.B25__Title__c).onUpdate(new CopyFieldHandler());
	}

	global class CopyFieldHandler extends B25.FormEventHandler {
		global override void handleEvent(B25.FormEvent event, B25.Form form) {
			B25.FormRecord activeRecord = form.getActiveRecord();
			Object titleValue = activeRecord.get(B25__Reservation__c.B25__Title__c);
			if (form.hasParentRecord()) {
				B25.FormRecord parentRecord = form.getParentRecord();
				if (parentRecord != activeRecord) {
					parentRecord.put(B25__Reservation__c.B25__Title__c, titleValue);
				}
			}
			if (form.hasChildRecords()) {
				for (FormRecord childRecord : form.getChildRecords()) {
					if (childRecord != activeRecord) {
						childRecord.put(B25__Reservation__c.B25__Title__c, titleValue);
					}
				}
			}
		}
	}
}