Salesforce has recently announced the Lightning Record Picker component. Lightning-record-picker is available in Beta and shall be Generally Available (GA) in Spring ’24.
Moreover, the Lightning Record Picker component in Lightning web components (LWC) provides a user-friendly interface for selecting records. This makes the process of associating records much easier and more intuitive.
One notable feature of the Lightning Record Picker is its offline capability, ensuring a consistent user experience whether users are working online or offline.
Additionally, it is designed to be compatible with both desktop and mobile platforms, thereby enhancing its versatility.
In this example, we are also creating a simple lightning record picker component to search the Account records. To initialize, all we need is a label for the input field, the object name from which particular data would be searched, and a callback to handle the selection of the record.
lightningRecordPicker.html
lightningRecordPicker.js
Output:
Also Read:Â Trigger Scenario-Based Questions in Salesforce
Lightning Record Picker with Dynamic Targets
The above example explains a Lighting record picker with a static filter, Let explore a lightning record picker with dynamic targets.
The record picker component offers strong capabilities to improve user interaction and data retrieval while integrating seamlessly with your page.
Additionally, you can add a placeholder, implement validation, and more. Moreover, this component provides various customizations that can be tailored based on our specific requirements.
1. Matching Fields: By default, it includes the object name. Moreover, on top of it, you can additionally display a field with text or formula field type. You can also use more fields for matching criteria.
2. Display Fields: Similarly, users appreciate it when we add a secondary field to aid in finding the correct record (especially when there are several records with similar names). Initially, we display the Name field.
3. Filtering: Record Picker gives you complete control over how records are filtered for your users, including the ability to mix custom logic, field types, and operators. Additionally, operator wildcards to SOQL are supported.
4. Validation: Validation is supported by the Record Picker component to guarantee user input and data integrity.
Validation messages may appear not only when you use the `reportValidity()` function but also when the component leaves focus. Moreover, SetCustomValidity() allows you to set custom validation messages as well.
lightningRecordPickerDynamic.html
lightningRecordPickerDynamic.js
Output :
In the above example, we have implemented the Lightning Record Picker with dynamic targets, incorporating various attributes such as DisplayInfo, matching info, and Filter.
Specifically, the Filter attributes include the Name field, ensuring that only account names containing “Company” will be displayed.
One thought on “Lightning Record Picker in Salesforce”