Skip to main content
Skip table of contents

Show only Contacts linked to the Account

This page demonstrates two ways in which you can filter Contacts:

  1. Filter the Contact lookup.

  2. 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 Quick Start Guide.

  • Make sure that the Account (B25__Account__c) and Contact (B25__Contact__c) fields are visible on the reservation form, as described in Add custom fields to the Reservation form.

Handler

Implement the following search handler:

CODE
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:

CODE
form.getLookup(B25__Reservation__c.B25__Contact__c).onSearch(new ContactSearchHandler());

This adds your handler to the Contact lookup.

Test your solution

  1. Go to the calendar.

  2. Create a new reservation.

  3. Select an account.

  4. Select a contact in the lookup. Notice how only contacts for the selected account are shown.

Filter the Reservation Contacts related list

Prerequisites

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:

CODE
form.getRelatedList(B25__ReservationContact__c.SObjectType).onSearch(new ContactSearchHandler());

This adds your handler to the Reservation Contacts related list.

Test your solution

  1. Go to the calendar.

  2. Create a new reservation.

  3. Select an account.

  4. Select a contact in the related list. Notice how only contacts for the selected account are shown.

Example of the final result

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.