Ad Code

How to check where lwc is used in Salesforce

Check where lwc used in salesforce

Searching for where a Lightning Web Component (LWC) is used in Salesforce can be challenging due to the absence of a native Where is this used? feature. This article discusses effective workarounds to help you identify LWC references within your org.

Additionally, consider supporting this IdeaExchange request to enable this feature here.


Method 1: Search in the Visual Studio Code editor

Create a Salesforce project in the VS code, authorize the org, and get all the metadata components

To avoid missing any references, ensure all metadata types are included in the package.xml file before retrieving the components from the org.

For this demonstration, we have added a newly created component (Name: assetDelivery) to the following list of components

AppPage, HomePage, RecordPage, UtilityBar, FlowScreen, Custom tab, Record Action, Global Action, Visualforce page

The component meta file is given below for reference

lwc metadata file

Click on the Search icon in the VS Code (1), enter the component name (2)

vs code search tab

VS Code will list all XML files that reference the Lightning Web Component


Method 2: Temporarily remove targets in the component meta file

Caution: This method should be used carefully and only in a Dev Sandbox. Ensure you revert any changes after testing to avoid potential defects.

Remove specific targets e.g., lightning__RecordAction and lightning__GlobalAction from the component’s metadata file and Attempt to deploy this file to the org.

Review the error messages generated during the check-in and identify the component references mentioned in the error messages.

lwc metadata file
After testing, revert the changes in your local to ensure the metadata remains intact.

Method 3: Using SOQL Query

Use the following SOQL query with the Use Tooling API checkbox set to True

SELECT 
    MetadataComponentId,
    MetadataComponentName,
    MetadataComponentType,
    RefMetadataComponentId,    
    RefMetadataComponentName,
    RefMetadataComponentType
FROM
    MetadataComponentDependency
WHERE
    RefMetadataComponentType = 'LightningComponentBundle'

salesforce inspector soql execution

(I used the Salesforce Inspector plugin; if you don't have it, you can use the Query Editor in the Developer Console)

Limitations:

  • This method does not retrieve references from all metadata types related to your Lightning Web Component (LWC).
  • For example, the query results did not include references from Flow and Visualforce Pages during our testing.

Learn more about the limitations of the Tooling API in the Salesforce documentation

Method 4: Using Org Check AppExchange product

Org Check is a user-friendly AppExchange package designed to analyze your org and identify technical debt. It can also be used to find references to Lightning Web Components (LWCs).

org check app in appexchange

Steps to Install and Use Org Check:

Go to the AppExchange and search for Org Check

Click the Get It Now button to install the package in your Salesforce instance

Select your Salesforce account and Click Install in Production

install appexchange package


Accept the terms and conditions, then click
Confirm and Install

install appexchange package


If prompted, log in to your Salesforce org to complete the installation

Once installed, you’ll see a success confirmation as shown below

install appexchange package


Assign the
Org Check Users permission set to your user

Search for Org in the App Launcher (1) and click on Org check (2)

salesforce app launcher


Click on Visual Components (1), then select Lightning Web Components (2). You can either search with the component name (3) or directly click on the LWC listed in the view.

org check app in salesforce


References will be shown in the popup

org check app in salesforce

Before installing Org Check, ensure that it complies with your org’s policies and security requirements. 

 
Conclusion

While Salesforce lacks a native feature to locate where LWCs are used, the methods outlined above provide effective workarounds. Depending on your needs, you can use VS Code searches, SOQL queries, metadata edits, or the Org Check AppExchange product to identify LWC references.

Don’t forget to support the IdeaExchange request to make this feature natively available in the future!  

Have you tried these methods to locate LWC references in your Salesforce org? Share your experience, and tips, or ask questions in the comments below—we’d love to hear from you!

Post a Comment

0 Comments