Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Overview
Excerpt |
---|
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.
Code Block |
---|
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
Code Block |
---|
String getSearchTerm() |
Returns the search term that the user has typed.
Return value: String
getDefaultResults
Code Block |
---|
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.
Return value: B25.SearchResult.Collection
getReservationgetForm
Code Block |
---|
B25__Reservation__c getReservation.Form getForm() |
Returns the reservation record Form object that the user is searching on.Return value: B25__Reservation__chas performed the search on. This can be useful to get more information about the other fields that have been filled in on the reservation, using the Form.getReservation method.
Return value: B25.Form
getConditions
Code Block |
---|
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()
.
Return value: List<String>
addCondition
Code Block |
---|
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:
Code Block |
---|
addCondition('Account = \'' + accountId + '\''); |
Parameters:
Name | Type | Description |
---|---|---|
condition | String | The condition that you want to add. |
getSearchFields
Code Block |
---|
List<String> getConditionsgetSearchFields() |
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()
.Return value: List<String>fields that will be queried for the search term.
Return value: List<String>
addSearchField
Code Block |
---|
void addSearchField(String fieldName) |
Adds a field to be queried for the search term. For example, if you also want to search for contacts by phone number, do the following:
Code Block |
---|
searchContext.addSearchField('HomePhone');
searchContext.addSearchField('MobilePhone'); |
If the user performing the search has no access to any of these fields, they are ignored. So if the user has no access to the MobilePhone field in the example above, only the HomePhone field is searched.
You can also search for fields on related records. For example, if you also want to search for contacts by account name, do the following:
Code Block |
---|
searchContext.addSearchField('Account.Name'); |
Parameters:
Name | Type | Description |
---|---|---|
fieldName | String | The API name of a field that you want to be searched. |
setLabelTemplate
Code Block |
---|
void setLabelTemplate(String template, List<String> mergeFields) |
This method lets you define what the label of each search result should be, based on one or more merge fields. For example, if you want to display your contact labels like this: LastName, FirstName (AccountName), you would do the following:
Code Block |
---|
searchContext.setLabelTemplate('{0}, {1} ({2})', new List<String>{'LastName', 'FirstName', 'Account.Name'}); |
The above would result in an output like this:
Image AddedIf the user performing the search has no access to any of these fields, they are replaced with an empty string.
By default (so if you would never call this method) only the record name is displayed as the label. This is the same as doing the following:
Code Block |
---|
searchContext.setLabelTemplate('{0}', new List<String>{'Name'}); |
Parameters:
Name | Type | Description |
---|---|---|
fieldName | String | The API name of a field that you want to be searched. |
On this page | |
---|---|
|