Versions Compared

Key

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

...

Expand
titleImmediately add all group members as reservation contacts when selecting a group.
Code Block
global with sharing class MyFormLogic implements B25.FormAPIForm.CustomizableCustomizer {
    global void customize(B25.Form form) {
        // Trigger MyGroupHandler when the Group field changes
        form.getField(B25__Reservation__c.B25__Group__c).onUpdate(new MyGroupHandler());
    }
    
    global with sharing class MyGroupHandler implementsextends B25.FormAPI.EventHandlerFormEventHandler {
        global override void handleEvent(B25.FormEvent event, B25.Form form) {
            // Get all members that belong to the group
            Id newGroupId = (Id) event.getNewValue();
            List<B25__Group_Membership__c> groupMembers = [SELECT B25__Contact__c FROM B25__Group_Membership__c WHERE B25__Group__c = :newGroupId];

            // Loop through the members and add the contact to the reservation contacts
            for(B25__Group_Membership__c groupMember : groupMembers){
                B25__ReservationContact__c reservationContact = new B25__ReservationContact__c();
                reservationContact.B25__Contact__c = groupMember.B25__Contact__c;
                form.getRelatedList(B25__ReservationContact__c.SObjectType).addRecord(reservationContact);
            }
            
            //This updates the quantity of the reservation to the amount of contacts in the group 
            form.getField(B25__Reservation__c.B25__Quantity__c).updateValue(groupMembers.size());
        }
    }
}
Expand
titleAdd an extra option to the reservation contact search that adds all contacts linked to the selected account as reservation contacts
Code Block
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__c = contact.Id
            ));
        }
    }
}
Code Block
languagejava
global class ReservationContactSearchHandler implementsextends B25.SearchContext.HandlerSearchHandler {
	global override B25.SearchResult.CollectionSearchResultCollection getSearchResults(B25.SearchContext searchContext) {
    	B25.SearchResult.Collection searchCollection = searchContext.getDefaultResults();
        B25.SearchResult.Collection updatedCollection = new B25.SearchResult.Collection();
        if (searchContext.form.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;
    }
}

...