Skip to main content

How to Build a Custom Global List View Component in LWC

Salesforce list views are indispensable for filtering and managing object records. However, built-in list views sometimes fall short when you need custom filtering UI, reusable navigation components, or bespoke layouts embedded across multiple Lightning App Builder pages. By building a custom Global List View component in Lightning Web Components (LWC), you gain full control over data presentation while leveraging standard Salesforce metadata.

In plain words: A custom Global List View LWC uses Salesforce User Interface API wire adapters (getListUi) to fetch available object list views dynamically, rendering them as interactive links or customized record tables anywhere in your Lightning App.

Prerequisites

  • Fundamental understanding of Lightning Web Components and wire adapters.
  • Salesforce DX CLI configured locally or access to a Developer Sandbox.
  • Appropriate object permissions for target Salesforce objects (e.g., Account).

Step 1: Set Up the Component Project

Initialize a new LWC component using VS Code or execute the following Salesforce CLI command in your terminal:

sf force lightning component create --type lwc --componentname globalListView --outputdir force-app/main/default/lwc

Step 2: Implement the JavaScript Controller

Open globalListView.js and wire the getListUi adapter from lightning/uiListApi to query list view metadata dynamically:

// globalListView.js
import { LightningElement, wire } from 'lwc';
import { getListUi } from 'lightning/uiListApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';

export default class GlobalListView extends LightningElement {
    listViews;
    error;

    @wire(getListUi, {
        objectApiName: ACCOUNT_OBJECT,
        listViewApiName: 'AllAccounts' // Replace with your target List View API Name
    })
    wiredListViews({ data, error }) {
        if (data) {
            this.listViews = data.lists;
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.listViews = undefined;
            console.error('Error fetching list views:', error);
        }
    }
}
Developer Trap: Hardcoding string API names for object names can cause issues during org deployments. Always import schema tokens like import ACCOUNT_OBJECT from '@salesforce/schema/Account' to preserve compile-time safety and dependency tracking.

Step 3: Render Component Markup

In globalListView.html, iterate over the retrieved list view data using template directives:

Real-Life Example: Presenting list view shortcuts dynamically inside a custom navigation sidebar on a Lightning Utility Bar or Home Page.
<!-- globalListView.html -->
<template>
    <lightning-card title="Global List Views" icon-name="utility:filter">
        <div class="slds-p-around_medium">
            <template if:true={listViews}>
                <ul class="slds-list_horizontal slds-has-dividers_right">
                    <template for:each={listViews} for:item="listView">
                        <li key={listView.id} class="slds-m-right_medium">
                            <a href={listView.url} target="_blank" rel="noopener noreferrer">
                                {listView.label}
                            </a>
                        </li>
                    </template>
                </ul>
            </template>
            
            <template if:true={error}>
                <p class="slds-text-color_error">Unable to load list views.</p>
            </template>

            <template if:false={listViews}>
                <template if:false={error}>
                    <p>No list views available.</p>
                </template>
            </template>
        </div>
    </lightning-card>
</template>

Step 4: Add Styling Rules

Define custom spacing or overrides inside globalListView.css:

/* globalListView.css */
.slds-p-around_medium {
    padding: 1rem;
}

.slds-m-right_medium {
    margin-right: 1rem;
}

Step 5: Deploy and Use in App Builder

Deploy the metadata to your org and expose it for page layout integration inside globalListView.js-meta.xml:

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>60.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>
</LightningComponentBundle>

You can now instantiate your component anywhere using standard component tags:

<c-global-list-view></c-global-list-view>
Key Summary: Global List View LWC
  • UI API Module: Wire data via getListUi imported from lightning/uiListApi.
  • Schema Binding: Use @salesforce/schema objects to pass safe target Object API names.
  • Flexible Layouts: Custom HTML enables table, card, or navigation bar representations of native list views.

Conclusion

Building a custom Global List View component in Lightning Web Components unlocks versatile possibilities for user interface architecture. By combining UI API adapters with standard SLDS styling, you deliver a responsive, tailored user experience across Salesforce Lightning pages.