This class represents a search being performed by the user. It allows you to get more information about the context of the search, as well as narrowing down the search results with additional conditions.
Example
This search handler adds an extra query condition to the SearchContext, in order to only show Contacts related to the selected Account.
global class MyContactSearch implements B25.SearchContext.SearchHandler {
public B25.SearchResult.Collection getSearchResults(B25.SearchContext searchContext) {
Id accountId = searchContext.getReservation().B25__Account__c;
if (accountId != null) {
searchContext.addCondition('AND Account = \' + accountId + '\'');
}
List<B25.SearchResult> results = searchContext.getDefaultResults();
return new B25.SearchResult.Collection(results);
}
}
Methods
getSearchTerm
String getSearchTerm()
Returns the search term that the user has typed.
Return value: String
getDefaultResults
B25.SearchResult.Collection getDefaultResults()
Returns a Collection wrapping the results that would be generated by Booker25, modified by any conditions defined (also see addCondition).
To access the individual results, call getResults() on the Collection.
Returns the reservation record that the user is searching on.
Return value: B25__Reservation__c
addCondition
void addCondition(String condition)
Adds a condition to narrow down the search results returned by getDefaultResults(). Functionally identical to calling getConditions().add(condition).
Dynamic references to parameters (i.e. ‘Account = :accountId’) will not work. Make sure to escape ids in the following way:
addCondition('Account = \'' + accountId + '\'');
Parameters:
Name
Type
Description
condition
String
The condition that you want to add.
getConditions
List<String> getConditions()
Returns the conditions that have already been defined. These will narrow down the search results returned by getDefaultResults(). As this is a reference to the actual list, you can still manipulate this list (such as adding or removing entries) before calling getDefaultResults().