...
Custom Form Logic for a high level overview
Quick Start Guide to help you get your first implementation up and running
API Reference for details on the methods and objects you can use
Detailed Code Samples
This section currently contains some quick examples without much explanation. For a more thoroughly detailed example, seea few detailed code samples intended as tutorials to give you more guidance:
...
...
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 | Add 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 class MyFormLogic implements B25. |
|
...
...
Customizer {
global void customize(B25.Form form) {
|
|
...
form.getLookup(B25__Reservation__c.B25__Contact__c).onSearch(new ContactSearchHandler());
|
|
...
...
...
...
...
...
ContactSearchHandler());
}
global |
|
...
...
...
...
...
...
...
SearchResultCollection getSearchResults(B25. |
|
...
...
...
searchContext.setMetaTemplate('{0}', new List<String>{'Account.Name'});
|
|
...
return searchContext.getDefaultResults();
}
|
|
...
title | Add extra options to the Reservation Contact search to add all Contacts of the current Account to the related list |
---|
...
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 {
global void customize(B25.Form form) {
// Trigger MyGroupHandler when the Group field changes
form.getField(B25__Reservation__c.B25__Group__c).onUpdate(new MyGroupHandler());
|
|
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
extends B25.FormEventHandler {
global override |
|
...
...
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 |
|
...
...
// 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_Lookup__c = groupMember.B25__Contact__c;
|
|
...
...
getRelatedList(B25__ReservationContact__c.SObjectType).addRecord(reservationContact);
}
|
|
...
...
...
...
//This updates the quantity of the reservation to the |
|
...
...
...
...
...
...
...
...
...
...
...
...
...
__Reservation__c.B25__Quantity__c).updateValue(groupMembers.size());
}
|
|
...
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) {
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 |
---|
| global class ReservationContactSearchHandler extends B25.SearchHandler {
global override |
|
...
...
SearchResultCollection getSearchResults(B25 |
|
...
.SearchContext searchContext) {
B25.SearchResultCollection searchCollection = searchContext.getDefaultResults();
B25 |
|
...
.SearchResultCollection updatedCollection = new B25.SearchResultCollection();
|
|
...
if (searchContext.getForm().getReservation().B25__Account__c != null) {
|
|
...
updatedCollection.addSearchResult(
|
|
...
...
title | Add an extra option to the reservation contact search that adds all contacts linked to the selected account as reservation contacts |
---|
...
...
...
...
...
SearchResult('all-contacts', 'Add all contacts linked to current account')
|
|
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
updatedCollection.addSearchResults(searchCollection.getSearchResults());
|
|
...
...
...
...
...
...
...
...
...
...
...
...
...
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) {
String newTitleValue |
|
...
= (String) event.getNewValue();
|
|
...
...
List<B25__Reservation_Status__c> matchingStatus = [SELECT Id FROM B25__Reservation_Status__c WHERE Name = :newTitleValue];
|
|
...
...
...
...
...
...
...
...
...
...
...
__Reservation__c.B25__Status__c).updateValue(matchingStatus[0].Id);
}
}
} |
|
Expand |
---|
title | Remove all reservation contacts if |
---|
|
...
the account field is cleared |
|
Code Block |
---|
global class ReservationAccountChangeHandler extends B25.FormEventHandler {
global override void handleEvent(B25.FormEvent event, |
|
...
...
Form form) {
String newAccountValue = (Id) event.getNewValue();
|
|
...
...
...
...
...
...
...
...
if (String.isBlank(newAccountValue)) {
for(B25.RelatedListItem item |
|
...
: form.getRelatedList(B25__ReservationContact__c.SObjectType).getItems()) {
|
|
...
...
...
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 void handleEvent(B25.FormEvent event, B25.Form form) {
|
|
...
title | Update the status to the status with the same name as the reservation title |
---|
...
...
Id newStatus = form.getReservation().B25__Status__c;
|
|
...
List<B25__Reservation_Status__c> reservationStatus = [SELECT Id, Name FROM B25__Reservation_Status__c WHERE id = :newStatus];
|
|
...
...
...
...
reservationStatus.isEmpty()) {
|
|
...
...
reservationStatus[0].Name == 'Completed') {
|
|
...
for(B25.RelatedListItem item : form.getRelatedList(B25__ |
|
...
ReservationContact__c.SObjectType). |
|
...
...
...
title | Remove all reservation contacts if the account field is cleared |
---|
...
...
...
...
...
item.getField(B25__ReservationContact__c.B25__CheckedIn__c).updateValue(true);
|
|
...
...
...
...
} else {
for(B25.RelatedListItem item : form.getRelatedList(B25__ReservationContact__c.SObjectType).getItems()) {
|
|
...
item.getField(B25__ReservationContact__c.B25__CheckedIn__c).updateValue(false);
}
}
}
} |
|
...
...
Adds the reservation contact back into the list when removed if the contact is the same as the selected contact on the reservation |
|
|
...
ReservationContactRemoveHandler extends B25.FormEventHandler {
global override void handleEvent(B25.FormEvent event, B25.Form |
|
...
...
...
...
...
...
removedReservationContact = |
|
...
(B25__ReservationContact__c) form.getRelatedList(B25__ |
|
...
...
.SObjectType).getItemByGuid(event.getGuid()).getRecord();
|
|
...
...
...
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) {
|
|
...
...
.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) + |
|
...
...
|
---|
title | Set the title of any newly created reservation to New Reservation |
---|
|
|
...
FormInitHandler extends B25.FormEventHandler {
global override void handleEvent |
|
...
...
.FormEvent event, B25.Form form) {
if (form.getReservation(). |
|
...
...
...
...
...
...
B25__Title__c).updateValue('New Reservation');
}
}
} |
|
...
...
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 |
|
...
...
...
...
String newNotesValue = (String) event.getNewValue();
|
|
...
...
...
if (!String.isBlank(newNotesValue)) {
|
|
...
...
...
...
if (newNotesValue.containsIgnoreCase('Checked In')) {
|
|
...
...
...
...
title | Set the title of any newly created reservation to New Reservation |
---|
...
...
form.getRelatedList(B25__ReservationContact__c.SObjectType).getitembyGuid(event.getGuid()).getField(B25__ReservationContact__c.B25__CheckedIn__c).updateValue(true);
|
|
...
...
...
} else if (newNotesValue.containsIgnoreCase('Checked Out')) {
|
|
...
...
...
...
form.getRelatedList(B25__ReservationContact__c.SObjectType).getitembyGuid(event.getGuid()).getField(B25__ |
|
...
...
B25__CheckedIn__c).updateValue( |
|
...
...
Display two contact names linked to the account as meta text on the search result |
|
|
...
AccountLookupSearchHandler extends B25. |
|
...
SearchHandler {
global override |
|
...
...
SearchResultCollection getSearchResults(B25. |
|
...
...
...
B25.SearchResultCollection collection = new B25.SearchResultCollection();
|
|
...
for (Account account : [SELECT Id, Name, (SELECT Name FROM Contacts LIMIT 2) FROM Account LIMIT 20]) {
|
|
...
List<String> metaTextArray = new List<String>();
for (Contact contact : account.Contacts) {
metaTextArray.add(contact.Name);
}
|
|
...
...
...
collection.addSearchResult(new B25.SearchResult(account.Id, account.Name).setMetaText(String.join(metaTextArray, ', ')));
}
return collection;
}
} |
|
...
...
If the status of the reservation is "completed" hide the title field, otherwise show |
|
Code Block |
---|
| 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 |
|
...
...
...
...
...
onUpdate(new MyStatusHandler());
}
|
|
...
global with sharing class MyStatusHandler extends B25.FormEventHandler {
global override void |
|
...
...
.FormEvent event, B25.Form form) {
Id newStatusId |
|
...
= (Id) event.getNewValue();
|
|
...
...
title | Display two contact names linked to the account as meta text on the search result |
---|
...
...
B25__Reservation_Status__c status = [
|
|
...
...
...
...
...
...
...
...
...
...
...
FROM B25__Reservation_Status__c
WHERE Id = :newStatusId
|
|
...
...
...
...
...
...
...
status.Name == 'Completed') {
form.getField(B25__Reservation__c.B25__Title__c).hide();
|
|
...
...
...
...
...
...
B25__Reservation__c.B25__Title__c).show();
}
|
|
...