Lookup Filter Examples
Various examples for record types, record status, roles, and complex configurations in lookup filters.
Required Editions
| Available in: both Salesforce Classic and Lightning Experience |
| Available in: All Editions except for Database.com. |
| User Permissions Needed | |
|---|---|
| To define lookup filters: | Customize Application |
Record Types in Lookup Filters
If the value of a relationship field should only consist of records with a particular record type, specify the record type in a lookup filter. For example, if the Account Name field on opportunities should only have accounts with a Customer Account custom record type, define the following lookup filter to restrict users to only creating or editing opportunities associated with accounts that have a Customer Account record type, excluding accounts with Partner Account and Competitor Account record types:
| Filter Criteria | Account Name: Account Record Type equals value Customer Account |
| Custom Error Message | Account does not exist or is not a customer account. |
| Lookup Window Text | You can only associate customer accounts to an opportunity. Search results only display customer accounts. |
Record Status in Lookup Filters
If the value of a relationship field should only consist of records with particular status, specify the status in a lookup filter. For example, consider a Job Application object with a relationship field that points to the Position object. If the relationship field should only have open positions, define the following lookup filter to restrict users to only creating or editing job applications for positions with the Status field set to Open:
| Filter Criteria | Position: Status equals value Open |
| Custom Error Message | Position does not exist or is not an open position. |
| Lookup Window Text | You can associate only open positions with job applications. Search results display open positions only. |
Profiles in Lookup Filters
When a business rule does not apply to users with every profile, use the Current User Profile global variable fields to define lookup
filters that only affect users with a particular profile.
For example, the following lookup filter on the Case object Account Name field restricts users with a “Domestic Sales” profile to only creating or editing opportunities associated with accounts that have a billing country of “USA” while allowing other users to associate opportunities with any account:
| Filter Criteria |
|
| Filter Logic |
(1 AND 2) OR 3
|
| Custom Error Message | Account does not exist or the account billing country is not USA. Domestic sales reps can only create opportunities for accounts in the United States. |
| Lookup Window Text | Search results show only United States accounts in the for domestic sales representatives. |
You can modify the above example to simultaneously restrict users with a “Global Sales” custom profile to only associating opportunities to accounts with a non-US billing country:
| Filter Criteria |
|
| Filter Logic |
(1 AND 2) OR (3 AND 4) OR 5
|
| Custom Error Message | Account does not exist or the account billing country is not in your sales area. Sales reps can only create opportunities for accounts in their sales area. |
| Lookup Window Text | Search results only display accounts in your region. |
If you do not include line 5 in the filter criteria, users who are not in Global Sales or Domestic Sales cannot select or save any values on account records.
Roles in Lookup Filters
When a business rule does not apply to users in every role, use the Current User Role global variable fields to define lookup
filters that only affect users with particular roles. For example, in a recruiting
application that has a Position object with a lookup field to a Compensation Package object,
you can restrict users from editing or creating positions that have an executive
compensation plan unless they are executive administrators or vice presidents. To do this,
define the following lookup filter on the Position object Compensation Package
Name field:
| Filter Criteria |
|
| Filter Logic |
((1 OR 2) AND 3) OR (4 OR 5)
|
| Custom Error Message | The compensation plan does not exist, or you have selected an executive compensation plan but do not have access to create executive positions. |
| Lookup Window Text | Search results only display compensation plans that are relevant to positions you are allowed to create. |
Include the condition you are testing and the opposite condition. In this example, lines 1, 2, and 3 of the filter criteria ensure that users who are not VPs or Executive Administrators cannot select Executive compensation plans, while lines 4 and 5 ensure that VPs and Executive Administrators can select Executive compensation plans.
Blank Values in Lookup Filters
Your lookup filter criteria might reference a field that users often leave blank. You can design your lookup filter criteria to accept blank values by using the Add Filter Logic in the filter criteria to create an OR condition. For example, if you have a Partner Contact custom field on opportunities, restrict the field to only allow contacts that are associated to an account with a Partner Account record type, or private contacts not associated with any account.
| Filter Criteria |
|
| Filter Logic |
1 OR 2
|
| Custom Error Message | The partner contact must be associated with a partner account, or must be a private contact. |
| Lookup Window Text | Search results only display contacts from partner accounts or your private contacts. |
User IDs in Lookup Filters
Using user IDs in optional lookup filters can significantly improve user efficiency by first showing lookup search dialog results that are most relevant to the user while still allowing users to see all results if necessary. For example, on a lookup field to accounts, you can create an optional lookup filter that restricts the search results to accounts that the user owns in the search lookup dialog results. If the user is looking for an account that someone else owns, the user can remove the filter.
| Filter Criteria | Current User: User ID equals Field Account: Owner ID |
| Lookup Window Text | By default, search results only display accounts you own. To search all accounts, click “Show all results.” |
Simple Dependent Lookups
If the value of a relationship field should depend on the value of another relationship field on the current record, specify the field to field comparison in the criteria. For example, if the case Contact Name field should only have contacts associated to the account specified in the case Account Name field, use the following lookup filter:
| Filter Criteria | Contact Name: Account ID equals field Case: Account ID |
| Custom Error Message | Contact does not exist or is not associated to the case account. |
| Lookup Window Text | Search results only display contacts associated to the case account. |
When comparing lookup fields in lookup filter criteria, Salesforce always uses the ID of the relationship field, not the name.
Complex Lookup Filters and Dependent Lookups
Achieving complex business rules with lookup filters often involves combing your rules with filter logic and fields of various types. For example, consider an app for booking conference rooms that has the following data model:
| Object | Fields |
|---|---|
| Meeting |
|
| Conference Room |
|
| Office |
|
The following lookup filter on the meeting Conference Room field restricts the valid values to conference rooms that have a projector if the meeting requires one, as well as the necessary number of seats:
| Filter Criteria |
|
| Filter Logic |
(1 OR 2) AND 3
|
| Custom Error Message | Conference room not found or is insufficient for your meeting. |
| Lookup Window Text | Search results only display conference rooms that can support your meeting requirements. |
To refine the valid values even further, incorporate the office where the conference room is located:
| Filter Criteria |
|
| Filter Logic |
(1 OR 2) AND 3 AND 4
|
| Custom Error Message | Conference room not found or is insufficient for your meeting. |
| Lookup Window Text | Search results only display conference rooms that can support your meeting requirements. |

