Versions Compared

Key

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

...

Expand
titleAdd an extra option to the reservation contact search that adds all contacts linked to the selected account as reservation contacts
Code Block
languagejava
global class ReservationContactAddedHandler extends B25.FormEventHandler {
    global override void handleEvent(B25.FormEvent event, B25.Form form) {
        B25__Reservation__c reservation = form.getReservation();
        if (reservation.B25__Account__c == null || event.getNewValue() != 'all-contacts') {
            return;
        }
        for (Contact contact : [SELECT Id FROM Contact WHERE AccountId = :reservation.B25__Account__c]) {
        	form.getRelatedList(B25__ReservationContact__c.SObjectType).addRecord(new B25__ReservationContact__c(
            	B25__Contact_Lookup__c = contact.Id
            ));
        }
    }
}
Code Block
languagejava
global class ReservationContactSearchHandler extends B25.SearchHandler {
	global override B25.SearchResultCollection getSearchResults(B25.SearchContext searchContext) {
    	B25.SearchResult.CollectionSearchResultCollection searchCollection = searchContext.getDefaultResults();
        B25.SearchResult.CollectionSearchResultCollection updatedCollection = new B25.SearchResult.CollectionSearchResultCollection();
        if (searchContext.formgetForm().getReservation().B25__Account__c != null) {
        	updatedCollection.addSearchResult(
                new B25.SearchResult('all-contacts', 'Add all contacts linked to current account')
                	.setPreventDefault(true)
                	.setIcon('standard:contact_list')
            );
        }
        updatedCollection.addSearchResults(searchCollection.getSearchResults());
        return updatedCollection;
    }
}

...

Expand
titleRemove all reservation contacts if the account field is cleared
Code Block
global class ReservationAccountChangeHandler extends B25.FormEventHandler {
    global override void handleEvent(B25.FormEvent event, B25.Form form) {
        String newAccountValue = (Id) event.getNewValue();
        if (String.isBlank(newAccountValue)) {
            for(B25.RelatedListItem item : form.getRelatedList(B25__ReservationContact__c.SObjectType).getItems()) {
                item.remove();
            }
        }
    }
}

...

Expand
titleAdds the reservation contact back into the list when removed if the contact is the same as the selected contact on the reservation
Code Block
languagejava
global class ReservationContactRemoveHandler extends B25.FormEventHandler {
    global override void handleEvent(B25.FormEvent event, B25.Form form) {
        B25__ReservationContact__c removedReservationContact = (B25__ReservationContact__c) form.getRelatedList(B25__ReservationContact__c.SObjectType).getItemByGuid(event.guidgetGuid()).getRecord();
        if (form.getReservation().B25__Contact__c == removedReservationContact.B25__Contact_Lookup__c) {
            form.getRelatedList(B25__ReservationContact__c.SObjectType).addRecord(removedReservationContact);
        }
    }
}

...

Expand
titleSet the title of any newly created reservation to New Reservation
Code Block
languagejava
global class FormInitHandler extends B25.FormEventHandler {
    global override void handleEvent(B25.FormEvent event, B25.Form form) {
        if (form.getReservation().Id == null) {
        	form.getField(B25__Reservation__c.B25__Title__c).updateValue('New Reservation');   
        }
    }
}
Expand
titleToggle the checked in checkbox based on if the notes field contains checked in or checked out
Code Block
global class ReservationContactNotesChangeHandler extends B25.FormEventHandler {
    global override void handleEvent(B25.FormEvent event, B25.Form form) {
        String newNotesValue = (String) event.getNewValue();
        if (!String.isBlank(newNotesValue)) {
            if (newNotesValue.containsIgnoreCase('Checked In')) {
                form.getRelatedList(B25__ReservationContact__c.SObjectType).getitembyGuid(event.guidgetGuid()).getField(B25__ReservationContact__c.B25__CheckedIn__c).updateValue(true);
            } else if (newNotesValue.containsIgnoreCase('Checked Out')) {
                form.getRelatedList(B25__ReservationContact__c.SObjectType).getitembyGuid(event.guidgetGuid()).getField(B25__ReservationContact__c.B25__CheckedIn__c).updateValue(false);
            }
        }
    }
}

...