Streamline Salesforce Record Search with A Customizable and Mobile-Friendly Salesforce Component
Shrikant Bagal ???
17x Salesforce Certified Architect | Expert in Integration & Automation | Award-Winning Innovator Driving Business Transformation
As a Salesforce Lightning developer, have you ever found it challenging to create a custom component for searching and selecting records? Well, Meet the Lightning Record Picker—a highly flexible and customizable Standard Lightning Web Component (LWC) that streamlines the process of finding and selecting Salesforce records, making it faster, easier, and adaptable to a variety of scenarios.
Efficient data management is crucial for Salesforce users, especially when it comes to quickly retrieving and interacting with records. The lightning-record-picker component simplifies this process, enabling both desktop and mobile users to search for and select Salesforce records with ease. This article will walk you through the component's setup, configuration, and key features, highlighting its benefits for enhancing record search capabilities.
What is the Lightning Record Picker?
The Lightning Record Picker is designed to help users quickly find and select Salesforce records from any object. This component is generic and reusable across a wide range of use cases and experiences. It’s also fully configurable, allowing you to control its behavior, fields, and filters.
Additionally, the component is mobile-friendly. It works offline, even if your internet connection drops—thanks to Salesforce's secure offline record support paired with GraphQL for seamless data access in offline scenarios.
Features and Capabilities
The Record Picker is flexible and customizable, making it suitable for various scenarios. Some key features include:
Similarities and Differences with lightning-input-field (Lookup)
Although the lightning-record-picker shares similarities with the lightning-input-field component used for lookup fields, there are key differences. The lightning-input-field component is built for use in record forms with limited customization, and it uses SOSL-like matching capabilities for lookup fields.
By contrast, the Record Picker offers full control over matching and display fields, as well as filtering and query logic, making it a more versatile solution for custom use cases.
Example: Search for Account Records
You can easily configure lightning-record-picker to search for specific Salesforce objects. Below is an example setup for searching Account records:
<lightning-record-picker
label="Accounts"
placeholder="Search Accounts..."
object-api-name="Account">
</lightning-record-picker>
This basic setup allows users to search for accounts and choose the correct record from a list of matching results.
Filtering Records
A significant feature of the component is the ability to apply filters, enabling you to narrow down the search results based on specific criteria. For instance, you can filter accounts where the name of the related parent doesn't start with "Acme." & Type of account not equal to "Partner"
filter = {
criteria: [
{ fieldPath: 'Website', operator: 'eq', value: 'https://www.grenoble.fr' },
{ fieldPath: 'Parent.Name', operator: 'like', value: 'Acme%' },
{ fieldPath: 'Type', operator: 'ne', value: 'Partner' }
],
filterLogic: '(1 OR 2) AND 3',
};
Here’s how you can use the filter in the component:
领英推荐
<lightning-record-picker
object-api-name="Account"
label="Accounts"
filter={filter}>
</lightning-record-picker>
Advanced Customizations: Display and Matching Information
You can also control how search results are displayed by configuring the display-info attribute. This lets you specify which fields to display in the results list.
For example, to display the Account Name as the primary field and Title as an additional field:
displayInfo = {
primaryField: 'Account.Name',
additionalFields: ['Title'],
};
<lightning-record-picker
object-api-name="Contact"
label="Contacts"
display-info={displayInfo}>
</lightning-record-picker>
Additionally, you can configure the fields the component searches by using the matching-info attribute. This allows you to search on fields beyond just the record name:
matchingInfo = {
primaryField: { fieldPath: 'Name' },
additionalFields: [{ fieldPath: 'Phone' }],
};
<lightning-record-picker
object-api-name="Contact"
label="Contacts"
matching-info={matchingInfo }>
</lightning-record-picker>
What’s on the Horizon for the Record Picker in the Next Release?
Record Picker Component Library Link: - https://developer.salesforce.com/docs/component-library/bundle/lightning-record-picker/documentation
#LightningRecordPicker #SalesforceLWC #SalesforceDevelopment #RecordPicker #LightningWebComponents #SalesforceCustomComponents #AdvancedFiltering #SalesforceFeatures #LWCUpdates