Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • How to Build a Generic Modal Window in Lightning Web Component
    • 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
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Thursday, May 29
    • 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»Configurable Record Picker in Lightning Web Component

    Configurable Record Picker in Lightning Web Component

    Dhanik Lal SahniBy Dhanik Lal SahniNovember 28, 2023Updated:January 15, 2025No Comments5 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Record Picker in LWC - SalesforceCodex
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Record Lookup is an interface element that allows users to choose specific records from objects. To use a record Lookup in Lightning Web Component, we used to create custom lookup components like Generic Multi-Select Lookup Component. Although this is for multi-select lookup and it will still be used as there is no record picker component to select multiple records. For single record selection, Salesforce has introduced a new Record Picker control lightning-record-picker to select object records in custom LWC (Lightning Web Component) screens. Now we don’t need to create a custom component for record lookup. This post will explain how to create a configurable record picker in LWC to make it more manageable in code.

    Configurable Record Picker Control will help us in changing filter criteria, and fields at runtime without changing code.

    How does Record Picker Control Work?

    Before using this control, let us see how this control works internally. Record Picker control uses a GraphQL Wire Adapter to search for records, show the records, and enable the user to pick one. As internally it is using GraphQL for searching records, we can use filtering of records as well as additional fields to display in lookup.

    We can show Record Picker for the Account object like the below code.

    <template>
        <lightning-card title="Record Picker">
            <lightning-record-picker
            label="Accounts"
            placeholder="Search Accounts..."
            object-api-name="Account">
            </lightning-record-picker>
        </lightning-card>
    </template>

    When this record picker is shown on the page and the record is looked up it will fire the GraphQL API request. We can check the network tab in the browser debugger to see the GraphQL request for the record search. In the below image, we can see the GraphQL API call.

    Callout 1 – When we search in the record picker, it will execute a GraphQL request by appending url parameter &aura.RecordUi.executeGraphQL=1

    Callout 2 – Request for GraphQL API with searched text.

    Record Picker in LWC - SalesforceCodex

    On the basis of the searched text, the result is returned from Salesforce Object and shown in record picker control.

    How to Use Record Picker?

    To use this element, we need at least two attributes object-api-name and label. object-api-name indicates the object for which the record will show and the label/header text is the caption for control.

    <template>
        <lightning-card title="Record Picker">
            <lightning-record-picker
            label="Accounts"
            object-api-name="Account">
            </lightning-record-picker>
        </lightning-card>
    </template>

    This control has below important properties

    matching-infoThis is field information that will show in the record picker. Like, show the name field for record selection.
    display-infoThis will show additional fields with the primary field (matching-info). Multiple additional fields can be shown. Like, show email and phone along with the primary name field.
    filterThis attribute is used to filter the record picker. Like, show only USA records

    Create a Configurable Record Picker Component

    The Record Picker component is perfect for a simple application but when we need full control over record selection then we have to customise it.

    We can customize all attributes but I have customized only the above 3 attributes (matching-info,display-info and filter). To make it customizable, I have created 2 custom metadata types.

    Record Picker Config custom metadata type will hold object and field information that will be shown in Record Picker. Create custom fields based on the below images in this metadata type.

    Record Picker Configuration - SalesforceCodex

    Add records in this metadata object.

    Developer NameDisplay Field NameDisplay Secondary FieldsObject API
    Account_Picker_On_Patient_PageNameEmail__c, PersonPhoneAccount

    We can add comma-separated fields in Display Secondary Fields to show multiple additional fields.

    Record Picker Condition Configuration - SalesforceCodex

    Field Condition Operator is the list of operators to be used with the filter field. This is required when GraphQL will search using filter criteria. Put these values in the Field Condition Operator picklist.

    Record Picker Condition Operator - SalesforceCodex

    Add records in this metadata object.

    Record Picker ConfigCondition FieldCondition OperatorCondition Value
    Account_Picker_On_Patient_PageNameLikea%

    We are ready with configuration object creation. We also created configuration records.

    Apex Class

    We need to create an apex class that will fetch configuration records from the custom metadata type based on the provided config name.

    Let us create a Lightning Web Component to make a Configurable Record Picker. It will use the above-created apex class RecordPickerController to fetch the record picker configuration. Based on the retrieved configuration lightning-record-picker control’s properties are set.

    The component is configured to be directly used on the record page. We can also use it in the other LWC components. In the below code, Account_Picker_On_Patient_Page is the record picker config record name.

    <c-object-record-picker record-picker-config-name='Account_Picker_On_Patient_Page' label='Account' place-holder='Select Account'></c-object-record-picker>

    I have not added configuration code related to literal values. We can use the Is Literal field to set literal value. If you need help with this configuration, let us connect.

    Use Created Component in Record Page

    Record Picker in Record Page - SalesforceCodex

    Demo Video For Record Picker

    References

    lightning-record-picker – documentation

    Introducing the Lightning Record Picker Component

    Related Posts

    Exploring GraphQL API in Salesforce

    Generate GraphQL Query in Salesforce Apex

    Dynamically Instantiate Components in LWC

    Low Code Integration for Text Translation using Systran API

    Extract Demographic Details using Trestle Reverse Phone API

    Verify Phone in Salesforce using VeriPhone API

    Named Entity Recognition using Salesforce Einstein API

    AWS Signature 4 Signing in Salesforce

    Upload File to AWS S3 Server

    Need Help?

    Need some kind of help in implementing this feature, connect on my LinkedIn profile Dhanik Lal Sahni.

    apex lightning Lightning web component lwc record lookup record picker salesforce salesforce apex
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleDisplaying Tabular Data with GraphQL in Lightning Web Component
    Next Article Migrating Salesforce Metadata with Git
    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 Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    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
    Add A Comment
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • 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
    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 (111) 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) file upload (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 (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) 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
    • How to Build a Generic Modal Window in Lightning Web Component
    • 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
    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 (111) 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) file upload (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 (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) 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.