BUSINESS CHALLENGE
A Lookup relation essentially links two objects together so that you can “look up” one objects’ record from another objects’ record.
What if you want to filter the records that appear in the look up search based on certain criteria?
The Lookup relationship field in Salesforce has Lookup Filter option where you can filter the records that are visible in the lookup search. Using comparison operators we can either equate a fields’ value to a specific value(hardcoded) or any other fields’ value.
LOOKUP FILTER CRITERIA USING HARDCODED VALUE
-
Here we have two record types in Account i.e. Competitor and Customer.
-
Click Object Manager →Type Opportunity in the Quick find box → Select Opportunity Object.
-
Select Fields and Relationship → Click New.
-
Select Lookup Relationship → Click Next.
-
Select Related To Object as Accounts → Click Next.
-
Enter Field Label as Competitor Account and the Field Name will be Auto populated.
-
Scroll down and under Lookup Filter expand Show Filter Settings. For the field Select Competitor Account: Account Record Type, choose equals as operator, for Value/Field choose Value since we are using a Hardcoded value and enter Competitor as the value.
-
Click Next.
-
Set Field Visibility for the required Profiles. → Click Next.
-
Select the required Page Layout → Click Next.
-
Click Save.
TESTING
-
Here we have created two customer accounts and two competitor accounts.
-
Go to Opportunity record Page → Select any Opportunity record.
-
Click Edit.
-
Place Cursor in the Competitor Account field and only the competitor Accounts will be displayed. Please refer to the image below.
LOOKUP FILTER CRITERIA USING A FILEDS’ VALUE
-
From the home page click on Gear Icon at the top, go to Setup.
-
In the Quick Find search and Select Opportunity.
-
Select Field and Relationship → Click New.
-
Select Data Type as Lookup Relationship → Click Next.
-
Select Contact object in Related to field.
-
Click Next.
-
Based on your requirement fill the field label and API name will be populated automatically.
-
Scroll down and expand Show Filter Settings.
-
Choose Current Record i.e. Opportunity and select Account Id,
Choose Equals as the Operator, Choose Field in Value / Field,
Select Current Lookup i.e. Contact and choose the Account ID field.
-
Click Next.
-
Select the Profile based on your requirement → Click Next.
-
Add the created field to the Page Layout.
-
Click Next.
-
Click Save.
TESTING
Create an account “Burlington Textiles Corp of America”
This Account is connected with a Contact “Mr. Jack Rogers”
While creating an Opportunity record select Existing Account Record in Account Name. The contact lookup field will only show the contacts related to the selected Account.
WRAPPING IT UP
In this blog we have covered how to add Filter Criteria while creating a Lookup Field using a hardcoded value as well as a field.
Leave a Comment