Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    • Enhancing Performance with File Compression in Apex
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Tuesday, May 20
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Apex»Generic Multi-Select Lookup Component

    Generic Multi-Select Lookup Component

    Dhanik Lal SahniBy Dhanik Lal SahniJanuary 5, 2023Updated:January 12, 20254 Comments4 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Generic multi select lookup
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Multi Select lookup or pick list selector is one of the important components in the Salesforce Application. We have a Lookup and Multi Select Pick list component in Screen Flow that will support multi-selection but for selecting multiple options we have to search again and then pick an option. For an end user, this could be a problem for multi-option selection. In this post, we will create a generic multi-select lookup component that can be used in a flow, other lightning web component, or lightning app builder page.

    The component will also support showing additional 2 fields in choice. These additional fields are optional.

    Check our other blog Multi Select Lookup in Screen Flow for standard multi-select lookup.

    Steps for creating a generic multi-select lookup component

    1. Creating Apex Class for Lookup
    2. Creating Generic LWC for Multi-Select Lookup Component
    3. Test Component in Flow
    4. Test Component in Another LWC

    1. Creating Apex Class for Lookup

    Let us create an apex class that will search based on input criteria. We will create a searchRecords method which will require data in SearchRequest data wrapper. This wrapper has below properties

    PropertyDescription
    searchKeyinput text for searching records in object {objectName}. This will be searched as like in {titleFieldName} field.
    objectNameObject API for lookup
    titleFieldNameField API for options
    subTitleFieldNameField API for options. This will be shown as additional field information like SalesforceCodex(salesforcecodex.com)
    subTitle2FieldNameField API for options. This will be shown as additional field information like SalesforceCodex(salesforcecodex.com-Dhanik Lal Sahni)
    queryConditionOptional Filter criteria for query records. like Active__c=true or MailingAddressState=’CA’
    selectedRecIdsAdditional search criteria. This will be used to skip existing selected records.

    Here is apex class code for searching records based on input criteria.

    The class will return result in a list of SearchResult wrapper class.

    record– It will return sObject so that we can retrieve the required fields in LWC. We are not hardcoding fields so we have to return sObject. We are not returning too many fields, only fields mentioned in the input criteria are returned. This will be also required as we can get the parent field in the option as well.

    recordId– It is the record id.

    recordName– Name field value. You can skip parameters.

    we have used dynamic query to fire query in the database as we don’t know for which object this lookup will be used.

    2. Creating Generic LWC for Multi-Select Lookup Component

    Let us create now LWC for generic lookup. As it will be generic, we have to get all required object detail from the caller so that we can prepare a lookup for a given object. We will create the below public properties in LWC which can be used and passed information by the caller.

    propertyProperty Description
    labelNameIt is label for lookup. Like Contact Address etc.
    placeHolderIt is a place holder which will be shown in the search field.
    titleFieldNamePrimary field API which is required for lookup. Like Name
    subTitleFieldNameOptional subtitle field to show in the list. It will display values like SalesforceCodex(salesforcecodex.com)
    subTitle2FieldNameOptional Sub Title 2 field. It will display values like SalesforceCodex(salesforcecodex.com-Dhanik Lal Sahni)
    objectApiNameObject API Name.
    iconNameIcon name for the object. Refer SLDS icon for this.
    lookupConditionOptional Filter criteria for query records. like Active__c=true or MailingAddressState=’CA’
    selectedRecordIdsIt is an output detail that is updated when options are selected/deselected.
    removedRecordIdsRemoved option ids.
    addedRecordIdsNewly added options ids.

    Above properties will help us in creating a generic components. Important code block of this component are below

    connectedCallback – On component load, it will show selected records as lightning-pill

    setOptions – This will set option title. If subtitle is there then set title as title (subtitle). If subTitle and subTitle2 are there then set title as title (subTitle-subTitle2)

    raiseEvent– On check box selection raise an event for the caller component with selected options

    searchText– Search and display options based on input text criteria.

    LWC Code

    3. Test Component in Flow

    We have completed the development of the generic lookup component. let us test this component in screen flow.

    Add component Multi Selection Lookup (this is name of our generic component. You can change that in js-meta.xml file) on screen element and set properties for this component.

    API Name – accountLookup

    Add filter condition – Leave blank

    Icon Name – standard:account

    Label Name– Select Account

    Object API Name– Account

    Search Placeholder– Search Account

    Selected Record Ids– Leave blank

    Sub Title Field Api– PersonEmail

    Sub Title2 Field Api– Leave blank

    Title Field Api– Name

    Test Lookup Image:

    Yellow is our titleField and red is subTitle field.

    generic multi-select lookup | lookup component in LWC

    4. Test Component in Another LWC

    Let us add a generic lookup component in another LWC to test its functionality. For testing purpose, i have added one alert on checkbox selection. You can add funcationality based on your requirement.

    Test Video:

    References:

    Pill

    Dynamic SOQL

    Related Posts:

    Multi Select Lookup in Screen Flow

    apex lightning lightning component Lightning web component lookup lookup component lookup in lwc lwc multi select lookup multi select picklist picklist in lwc salesforce salesforce apex search component in lwc
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleSecure Apex Code with User Mode Operation
    Next Article Generic Notification Component in LWC
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    By Dhanik Lal Sahni5 Mins Read

    How to Implement Dynamic Queueable Chaining in Salesforce Apex

    April 21, 2025
    View 4 Comments

    4 Comments

    1. Pingback: On-Demand Email-to-Case and Email-to-Case - SalesforceCodex

    2. Pingback: Web-to-Case and Email-to-Case - SalesforceCodex

    3. Pingback: Multi Select Lookup in Screen Flow - SalesforceCodex

    4. Pingback: What is Salesforce Genie? - Salesforce Codex

    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (110) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) einstein (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (29) Lightning web component (61) lwc (50) named credential (8) news (4) optimize apex (3) optimize apex code (4) Permission set (4) Queueable (9) rest api (23) S3 Server (4) salesforce (140) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (110) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) einstein (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (29) Lightning web component (61) lwc (50) named credential (8) news (4) optimize apex (3) optimize apex code (4) Permission set (4) Queueable (9) rest api (23) S3 Server (4) salesforce (140) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.