Streamline Salesforce Record Search with A Customizable and Mobile-Friendly Salesforce Component

Streamline Salesforce Record Search with A Customizable and Mobile-Friendly Salesforce Component

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:

  • Configurable Search and Display Fields: The default behavior matches the object's Name field, but you can override this to match other fields like text or text-formula fields. You can also configure secondary fields to display additional context in search results.
  • Filtering: With comprehensive support for field types, operators, and custom logic, you can filter records in various ways to find exactly what you need. The Record Picker supports SOQL-like wildcard matching.
  • Validation: The component supports built-in validation, ensuring data integrity and user input accuracy. You can customize validation messages and display them when the component loses focus or by using the reportValidity() method.

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?

  • Advanced Querying Capabilities: Support for SOSL to provide even more powerful search options.
  • Platform Actions Integration: The ability to create or modify records directly within the Record Picker.
  • Most Recently Used Records (MRUs): Quick access to frequently used records.
  • Multi-Select Mode: Select multiple records at once.
  • Dynamic Target Object Mode: Allow users to choose records from different target objects.


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



要查看或添加评论,请登录

社区洞察

其他会员也浏览了