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
Click on the Search icon in the VS Code (1), enter the component name (2)
VS Code will list all XML files that reference the
Lightning Web Component
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.
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'
(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).
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
Accept
the terms and conditions, then click Confirm and Install
If
prompted, log in to your Salesforce org to complete the installation
Once installed, you’ll see a success confirmation as shown below
Assign
the Org Check Users permission set to your user
Search
for Org in the App Launcher (1) and click on Org check (2)
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.
References
will be shown in the popup
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!
0 Comments