back to blog
LookUp Filter
September 14 2022 • 10 min read

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

  1. Here we have two record types in Account i.e. Competitor and Customer.

    lfb 1

  2. Click Object Manager →Type Opportunity in the Quick find box → Select Opportunity Object.

  3. Select Fields and Relationship → Click New.

    lfb 2

  4. Select Lookup Relationship → Click Next.

  5. Select Related To Object as Accounts → Click Next.

  6. Enter Field Label as Competitor Account and the Field Name will be Auto populated.

    lfb 3

  7. 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.

    lfb 4

  8. Click Next.

  9. Set Field Visibility for the required Profiles. → Click Next.

  10. Select the required Page Layout → Click Next.

  11. Click Save.

    lfb 5

TESTING

  1. Here we have created two customer accounts and two competitor accounts.

    lfb 6

  2. Go to Opportunity record Page → Select any Opportunity record.

  3. Click Edit.

  4. Place Cursor in the Competitor Account field and  only the competitor Accounts will be displayed. Please refer to the image below.

    lfb 7

LOOKUP FILTER CRITERIA USING A FILEDS’ VALUE

  1. From the home page click on Gear Icon at the top, go to Setup.

    lfb 8

  2. In the Quick Find search and Select Opportunity.

  3. Select Field and Relationship → Click New.

    lfb 9

  4. Select Data Type as Lookup Relationship → Click Next.

    lfb 10

  5. Select Contact object in Related to field. 

    lfb 11

  6. Click Next.

  7. Based on your requirement fill the field label and API name will be populated automatically.

    lfb 12

  8. Scroll down and expand Show Filter Settings.

    lfb 13

  9. 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.

lfb 14

  1. Click Next.

  2. Select the Profile based on your requirement → Click Next.

    lfb 15

  3. Add the created field to the Page Layout.

    lfb 16

  4. Click Next.

    lfb 17

  5. 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.

lfb 18

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

Your email address will not be published

© 2024 Digital Biz Tech