...
Quick and Dirty Code Samples
This section contains some quick examples without much explanation, intended to give you some more ideas of what is possible.
Expand |
---|
title | Immediately add all group members as reservation contacts when selecting a groupAdd the Account name to all Contact searches |
---|
|
This example adds the Account name to each Contact appearing in the Contact lookup and Contact related list. Code Block |
---|
global with sharing class MyFormLogic implements B25.Form.Customizer {
global void customize(B25.Form form) {
// Trigger MyGroupHandler when the Group field changesform.getLookup(B25__Reservation__c.B25__Contact__c).onSearch(new ContactSearchHandler());
form.getFieldgetRelatedList(B25__ReservationReservationContact__c.B25__Group__cSObjectType).onUpdateonSearch(new MyGroupHandlerContactSearchHandler());
}
global with sharing class MyGroupHandlerContactSearchHandler extends B25.FormEventHandlerSearchHandler {
global override void handleEvent(B25.FormEvent event, SearchResultCollection getSearchResults(B25.FormSearchContext formsearchContext) {
// Get all members that belong to the groupsearchContext.setMetaTemplate('{0}', new List<String>{'Account.Name'});
return searchContext.getDefaultResults();
Id newGroupId = (Id) event.getNewValue();}
}
} |
|
Expand |
---|
title | Immediately add all group members as reservation contacts when selecting a group. |
---|
|
Code Block |
---|
global with sharing class MyFormLogic implements B25.Form.Customizer {
List<B25__Group_Membership__c> groupMembers =global [SELECTvoid B25__Contact__c FROM B25__Group_Membership__c WHERE B25__Group__c = :newGroupId];
customize(B25.Form form) {
// LoopTrigger throughMyGroupHandler the members and add when the contactGroup tofield thechanges
reservation contacts for(form.getField(B25__Reservation__c.B25__Group_Membership__c groupMember : groupMembers){).onUpdate(new MyGroupHandler());
}
global B25__ReservationContact__c reservationContact = new B25__ReservationContact__c();
with sharing class MyGroupHandler extends B25.FormEventHandler {
global override void handleEvent(B25.FormEvent event, B25.Form reservationContact.B25__Contact_Lookup__c = groupMember.B25__Contact__c;form) {
// Get all members that belong to the group
form.getRelatedList(B25__ReservationContact__c.SObjectType).addRecord(reservationContact); Id newGroupId = }(Id) event.getNewValue();
List<B25__Group_Membership__c> groupMembers = [SELECT B25__Contact__c FROM B25__Group_Membership__c //This updates the quantity of the reservationWHERE B25__Group__c = :newGroupId];
// Loop through the members and add the contact to the amount ofreservation contacts in the group
form.getFieldfor(B25__ReservationGroup_Membership_c.B25__Quantity__c).updateValue(groupMembers.size());c groupMember : groupMembers){
} } } |
|
Expand |
---|
title | Add 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 {
B25__ReservationContact__c reservationContact = new B25__ReservationContact__c();
global override void handleEvent(B25.FormEvent event, B25.Form form) { reservationContact.B25__Contact_Lookup__c = groupMember.B25__ReservationContact__c;
reservation = form.getReservation(); if (reservationform.getRelatedList(B25__AccountReservationContact__c == null || event.getNewValue() != 'all-contacts') {.SObjectType).addRecord(reservationContact);
}
return; }
for (Contact contact : [SELECT Id//This FROMupdates Contactthe WHEREquantity AccountIdof =the :reservation.B25__Account__c]) {reservation to the amount of contacts in the group
form.getRelatedListgetField(B25__ReservationContactReservation__c.SObjectType).addRecord(new B25__ReservationContactQuantity__c).updateValue(groupMembers.size());
}
B25__Contact__c = contact.Id
}
} |
|
Expand |
---|
title | Add 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) {
}
} } | Code Block |
---|
| global class ReservationContactSearchHandler extends B25.SearchHandler {
global override B25.SearchResultCollection getSearchResults(B25.SearchContext searchContext) {B25__Reservation__c reservation = form.getReservation();
B25.SearchResult.Collection searchCollection =if searchContext.getDefaultResults();(reservation.B25__Account__c == null || event.getNewValue() != 'all-contacts') {
B25.SearchResult.Collection updatedCollection = new B25.SearchResult.Collection(); return;
}
if (searchContext.form.getReservation(). for (Contact contact : [SELECT Id FROM Contact WHERE AccountId = :reservation.B25__Account__c != null]) {
updatedCollection.addSearchResult(
form.getRelatedList(B25__ReservationContact__c.SObjectType).addRecord(new B25__ReservationContact__c(
new B25.SearchResult('all-contacts', 'Add all contacts linked to current account') B25__Contact_Lookup__c = contact.Id
));
}
.setPreventDefault(true) }
} |
Code Block |
---|
| global class ReservationContactSearchHandler extends B25.SearchHandler {
global override B25.SearchResultCollection .setIcon('standard:contact_list')
getSearchResults(B25.SearchContext searchContext) {
B25.SearchResultCollection searchCollection = searchContext.getDefaultResults();
}B25.SearchResultCollection updatedCollection = updatedCollection.addSearchResults(searchCollection.getSearchResults())new B25.SearchResultCollection();
return updatedCollection;
}
} |
|
Expand |
---|
title | Update the status to the status with the same name as the reservation title |
---|
|
Code Block |
---|
| global class ReservationTitleUpdateHandler extends B25.FormEventHandler {
global override void handleEvent(B25.FormEvent event, B25.Form form) {if (searchContext.getForm().getReservation().B25__Account__c != null) {
updatedCollection.addSearchResult(
new B25.SearchResult('all-contacts', 'Add all Stringcontacts newTitleValuelinked =to (String) event.getNewValue();current account')
List<B25__Reservation_Status__c> matchingStatus = [SELECT Id FROM B25__Reservation_Status__c WHERE Name = :newTitleValue]; .setPreventDefault(true)
if (!matchingStatus .isEmpty()) {setIcon('standard:contact_list')
);
}
form.getField(B25__Reservation__c.B25__Status__c).updateValue(matchingStatus[0].Id); updatedCollection.addSearchResults(searchCollection.getSearchResults());
return }updatedCollection;
}
} |
|
Expand |
---|
title | Remove all reservation contacts if the account field is clearedUpdate the status to the status with the same name as the reservation title |
---|
|
Code Block |
---|
| global class ReservationAccountChangeHandlerReservationTitleUpdateHandler extends B25.FormEventHandler {
global override void handleEvent(B25.FormEvent event, B25.Form form) {
String newAccountValuenewTitleValue = (IdString) event.getNewValue();
if (String.isBlank(newAccountValue)) {
List<B25__Reservation_Status__c> matchingStatus = [SELECT Id FROM B25__Reservation_Status__c WHERE Name = :newTitleValue];
for(RelatedListItem item :if form.getRelatedList(B25__ReservationContact__c.SObjectType).getItems(!matchingStatus.isEmpty()) {
item.remove(form.getField(B25__Reservation__c.B25__Status__c).updateValue(matchingStatus[0].Id);
}
}
}
} |
|
Expand |
---|
title | Set Remove all reservation contacts to checked in if the status is set to completedaccount field is cleared |
---|
|
Code Block |
---|
global class ReservationStatusChangeHandlerReservationAccountChangeHandler extends B25.FormEventHandler {
global override void handleEvent(B25.FormEvent event, B25.Form form) {
IdString newStatusnewAccountValue = form.getReservation().B25__Status__c;(Id) event.getNewValue();
if List<B25__Reservation_Status__c> reservationStatus = [SELECT Id, Name FROM B25__Reservation_Status__c WHERE id = :newStatus];(String.isBlank(newAccountValue)) {
for(B25.RelatedListItem item : form.getRelatedList(B25__ReservationContact__c.SObjectType).getItems()) {
if (reservationStatusitem.isEmptyremove());
{ }
return;
}
if (reservationStatus[0].Name == 'Completed')}
} |
|
Expand |
---|
title | Set all reservation contacts to checked in if the status is set to completed |
---|
|
Code Block |
---|
global class ReservationStatusChangeHandler extends B25.FormEventHandler {
global override forvoid handleEvent(B25.RelatedListItemFormEvent item : form.getRelatedList(B25__ReservationContact__c.SObjectType).getItems())event, B25.Form form) {
Id newStatus item.getField(B25__ReservationContact__c= form.getReservation().B25__CheckedInStatus__c).updateValue(true);
List<B25__Reservation_Status__c> reservationStatus = [SELECT }Id, Name FROM B25__Reservation_Status__c WHERE id = :newStatus];
} else { if (reservationStatus.isEmpty()) {
for(B25.RelatedListItem item : form.getRelatedList(B25__ReservationContact__c.SObjectType).getItems()) { return;
}
item.getField if (reservationStatus[0].Name == 'Completed') {
for(B25.RelatedListItem item : form.getRelatedList(B25__ReservationContact__c.B25__CheckedIn__cSObjectType).updateValuegetItems(false)); {
} item.getField(B25__ReservationContact__c.B25__CheckedIn__c).updateValue(true);
}
}
} |
|
Expand |
---|
title | Adds the reservation contact back into the list when removed if the contact is the same as the selected contact on the reservation |
---|
|
Code Block |
---|
| global class ReservationContactRemoveHandler extends B25.FormEventHandler {
global override void handleEvent(B25.FormEvent event, B25.Form form) { else {
for(B25.RelatedListItem item : form.getRelatedList(B25__ReservationContact__c.SObjectType).getItems()) {
item.getField(B25__ReservationContact__c.B25__CheckedIn__c).updateValue(false);
}
}
}
} |
|
Expand |
---|
title | Adds the reservation contact back into the list when removed if the contact is the same as the selected contact on the reservation |
---|
|
Code Block |
---|
| 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.getGuid()).getRecord();
if (form.getReservation().B25__Contact__c == removedReservationContact.B25__Contact_Lookup__c) {
form.getRelatedList(B25__ReservationContact__c.SObjectType).addRecord(removedReservationContact);
}
}
} |
|
Expand |
---|
title | Randomise the icons on the resource lookup search results |
---|
|
Code Block |
---|
global class ResourceLookupSearchHandler extends B25.SearchHandler {
global override B25.SearchResultCollection getSearchResults(B25.SearchContext searchContext) {
B25.SearchResultCollection searchCollection = searchContext.getDefaultResults();
for (B25.SearchResult result : searchCollection.getSearchResults()) {
result.setIcon(this.getRandomIconName());
}
return searchCollection;
}
private String getRandomIconName() {
return 'custom:custom' + String.valueOf(Math.Round(Math.Random() * (113-1) + 1));
}
} |
|
Expand |
---|
title | Set the title of any newly created reservation to New Reservation |
---|
|
Code Block |
---|
| 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 |
---|
title | Toggle 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.getGuid()).getField(B25__ReservationContact__c.B25__CheckedIn__c).updateValue(true);
} else if (newNotesValue.containsIgnoreCase('Checked Out')) {
B25__ReservationContact__c removedReservationContact = (B25__ReservationContact__c) form.getRelatedList(B25__ReservationContact__c.SObjectType).getItemByGuidgetitembyGuid(event.guidgetGuid().getRecord();
if (form.getReservation()..getField(B25__ContactReservationContact__c == removedReservationContact.B25__ContactCheckedIn__c) {
).updateValue(false);
form.getRelatedList(B25__ReservationContact__c.SObjectType).addRecord(removedReservationContact); }
}
}
} |
|
Expand |
---|
title | Randomise the icons Display two contact names linked to the account as meta text on the resource lookup search resultsresult |
---|
|
Code Block | global class ResourceLookupSearchHandler extends B25.SearchHandler {
global override B25.SearchResultCollection getSearchResults(B25.SearchContext searchContext) {
B25.SearchResultCollection searchCollection = searchContext.getDefaultResults();
for (B25.SearchResult result : searchCollection.getSearchResults() |
---|
| global class AccountLookupSearchHandler extends B25.SearchHandler {
global override B25.SearchResultCollection getSearchResults(B25.SearchContext searchContext) {
result.setIcon(this.getRandomIconName());
}B25.SearchResultCollection collection = new B25.SearchResultCollection();
for return(Account searchCollection;account : [SELECT Id, Name, }(SELECT Name FROM Contacts LIMIT 2) FROM Account LIMIT 20]) private{
String getRandomIconName() { return 'custom:custom' + String.valueOf(Math.Round(Math.Random() * (113-1) + 1));List<String> metaTextArray = new List<String>();
} } |
|
Expand |
---|
title | Set the title of any newly created reservation to New Reservation |
---|
|
Code Block |
---|
| global class FormInitHandler extends B25.FormEventHandler {
global override void handleEvent(B25.FormEvent event, B25.Form form) {for (Contact contact : account.Contacts) {
if (form.getReservation().Id == null) {metaTextArray.add(contact.Name);
form.getField(B25__Reservation__c.Title__c).updateValue('New Reservation'); }
} collection.addSearchResult(new B25.SearchResult(account.Id, account.Name).setMetaText(String.join(metaTextArray, }
} |
|
Expand |
---|
title | Toggle 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) { return collection;
}
} |
|
Expand |
---|
title | If the status of the reservation is "completed" hide the title field, otherwise show |
---|
|
Code Block |
---|
| global with sharing class MyFormLogic String newNotesValue = (String) event.getNewValue();
implements B25.Form.Customizer {
global void if (!String.isBlank(newNotesValue)customize(B25.Form form) {
// if (newNotesValue.containsIgnoreCase('Checked In')) {
This is where we will add our handlers to the form
form.getRelatedList(B25__ReservationContact__c.SObjectType).getitembyGuid(event.guid).getField(B25__ReservationContactReservation__c.B25__CheckedInStatus__c).updateValue(trueonUpdate(new MyStatusHandler());
}
} else if (newNotesValue.containsIgnoreCase('Checked Out')) {
global with sharing class MyStatusHandler extends B25.FormEventHandler {
global override void form.getRelatedListhandleEvent(B25__ReservationContact__c.SObjectType).getitembyGuid(event.guid).getField(B25__ReservationContact__c.B25__CheckedIn__c).updateValue(false);.FormEvent event, B25.Form form) {
Id }newStatusId = (Id) event.getNewValue();
} }
} |
|
Expand |
---|
title | Display two contact names linked to the account as meta text on the search result |
---|
|
Code Block |
---|
| global class AccountLookupSearchHandler extends B25.SearchHandler {B25__Reservation_Status__c status = [
global override B25.SearchResultCollection getSearchResults(B25.SearchContext searchContext) { SELECT Name
B25.SearchResultCollection collection = new B25.SearchResultCollection(); for (Account account : [SELECT Id, Name, (SELECT Name FROM Contacts LIMIT 2) FROM Account LIMIT 20]) {
FROM B25__Reservation_Status__c
WHERE Id = :newStatusId
List<String> metaTextArray = new List<String>()];
forif (Contact contact : account.Contactsstatus.Name == 'Completed') {
metaTextArrayform.add(contact.NamegetField(B25__Reservation__c.B25__Title__c).hide();
} else {
collectionform.addSearchResultgetField(new B25.SearchResult(account.Id, account.Name).setMetaText(String.join(metaTextArray, ', ')));B25__Reservation__c.B25__Title__c).show();
}
return}
collection; }
}
} |
|