SfSkills Domains Docs GitHub

Home / lwc / lwc-record-picker

lwc-record-picker

lightning-record-picker base component (Winter '24 GA): object/record filter, displayInfo/matchingInfo, graph-ql filters, accessibility. Replaces ad-hoc lookup inputs. NOT for a fully custom typeahead lookup — use lwc/lwc-custom-lookup.

Open the skill folder on GitHub


LWC Record Picker

Activate when an LWC needs a user to search and select a single Salesforce record. lightning-record-picker (GA Winter '24) is the official base component; it replaces custom combobox+search implementations and hand-rolled lightning-lookup equivalents with one declarative tag.

Before Starting

Core Concepts

Minimum markup

<lightning-record-picker
    label="Account"
    placeholder="Search Accounts"
    object-api-name="Account"
    onchange={handleChange}>
</lightning-record-picker>

event.detail.recordId on change carries the selected record Id.

display-info / matching-info

<lightning-record-picker
    object-api-name="Contact"
    display-info={displayInfo}
    matching-info={matchingInfo}>
</lightning-record-picker>
displayInfo = {
    primaryField: 'Name',
    additionalFields: ['Account.Name', 'Email']
};
matchingInfo = {
    primaryField: { fieldPath: 'Name' },
    additionalFields: [{ fieldPath: 'Email' }]
};

Filter (graph-QL)

filter = {
    criteria: [
        { fieldPath: 'IsActive', operator: 'eq', value: true }
    ]
};

Limits search results.

Preselection

Set value={preselectedRecordId}. The picker fetches display fields and shows the chip.

Common Patterns

Pattern: Filtered contact picker scoped to account

Filter on AccountId = :this.accountId; filter updates when the account context changes.

Pattern: Multi-object picker via toggle

Two <lightning-record-picker> elements toggled by a dropdown that selects the object API name.

Pattern: Reset on context change

Programmatically set value = null (or re-query) when context changes.

Decision Guidance

NeedComponent
Standard single-record lookuplightning-record-picker
Multi-record selectlightning-record-picker (not supported) → build custom
External objectlightning-record-picker does not support; custom
Enforce record-type filterUse filter criteria on RecordTypeId
Filter by complex formulaServer-side Apex + custom combobox
  1. Confirm object is supported (standard + most custom). External objects unsupported.
  2. Define display-info and matching-info — always set primaryField.
  3. Build filter with graph-QL criteria for scope.
  4. Wire onchange to capture selected Id and fetch additional record details.
  5. Add accessibility attributes: label is required; leverage built-in keyboard nav.
  6. Write jest test asserting change event dispatch.
  7. Migrate any legacy custom lookup components to this one.

Review Checklist

Salesforce-Specific Gotchas

  1. External Objects not supported. The picker targets standard/custom only.
  2. Person Account nuance — when Person Accounts are on, Account results include persons; filter if you want companies only.
  3. matching-info is required for custom search fields — without it, only primary field matches.

Output Artifacts

ArtifactDescription
Picker config templatedisplayInfo / matchingInfo / filter examples
Migration planLegacy custom lookup → record-picker
Jest test helperMock event dispatch

Package files