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
));
}
}
} |