Show only Contacts linked to the Account
This page demonstrates two ways in which you can filter Contacts:
Filter the Contact lookup.
Filter the Reservation Contacts related list.
Of course, the same principles apply to any other lookups or related lists, and you can implement this solution for your own custom lookups or releated lists.
Filter the Contact lookup
Prerequisites
Implement a form customizer class and make sure GoMeddo is configured to use it, as described in the first two sections of the https://gomeddo.atlassian.net/wiki/spaces/BPD/pages/1829372013.
Make sure that the Account (B25__Account__c) and Contact (B25__Contact__c) fields are visible on the reservation form, as described in https://gomeddo.atlassian.net/wiki/spaces/BPD/pages/983096.
Handler
Implement the following search handler:
global with sharing class ContactSearchHandler extends B25.SearchHandler {
global override B25.SearchResultCollection getSearchResults(B25.SearchContext context) {
Id accountId = context.getForm().getReservation().B25__Account__c;
if (accountId != null) {
context.addCondition('AccountId = \'' + accountId + '\'');
}
return context.getDefaultResults();
}
}
This handler first checks if the Account field on the reservation is set. If the Account is set, it adds a condition to the search context to filter the results based on the Account id. It then returns the results.
Customizer
Now add the following line to the customize method inside your customizer class:
form.getLookup(B25__Reservation__c.B25__Contact__c).onSearch(new ContactSearchHandler());
This adds your handler to the Contact lookup.
Test your solution
Go to the calendar.
Create a new reservation.
Select an account.
Select a contact in the lookup. Notice how only contacts for the selected account are shown.
Filter the Reservation Contacts related list
Prerequisites
Implement a form customizer class and make sure GoMeddo is configured to use it, as described in the first two sections of the https://gomeddo.atlassian.net/wiki/spaces/BPD/pages/1829372013.
Make sure that the Account (B25__Account__c) field is visible on the reservation form, as described in https://gomeddo.atlassian.net/wiki/spaces/BPD/pages/983096.
Make sure that the Reservation Contacts (B25__ReservationContact__c) related list is visible on the reservation form, as described in https://gomeddo.atlassian.net/wiki/spaces/BPD/pages/580878375.
Handler
The search handler for this example is the same as in the previous section (Filter the Contact lookup). Refer to that section if you have not yet created it.
Customizer
Now add the following line to the customize method inside your customizer class:
form.getRelatedList(B25__ReservationContact__c.SObjectType).onSearch(new ContactSearchHandler());
This adds your handler to the Reservation Contacts related list.
Test your solution
Go to the calendar.
Create a new reservation.
Select an account.
Select a contact in the related list. Notice how only contacts for the selected account are shown.
Example of the final result