Search code examples
salesforcesalesforce-lightningsalesforce-communities

How to get all referenced pages where i used my custom lightning component?


Is there any way to get all referenced pages where i used my custom lightning component using salesforce api.

Example: I created a custom lightning component page 'Reminder' and used into custom tab view in Record Page or replace existing record view using Edit Page option.

I need to find all page information where my custom lightning component referenced.

Please share if any helpful SOQL query or rest api exist for that .

Any guidance would be appreciated. Thanks


Solution

  • Personally, I use Linux, so I like to pull down the metadata definitions and then grep through them.

    You would first need to retrieve the relevant metadata with a metadata api retrieve call using your tool of choice. Here's a sample package manifest for performing a retrieval of the lightning definitions and related resources:

    $ cat package.xml 
    <?xml version="1.0" encoding="UTF-8"?>
    <Package xmlns="http://soap.sforce.com/2006/04/metadata">
        <types>
            <members>*</members>
            <name>AuraDefinitionBundle</name>
        </types>
        <version>43.0</version>
    </Package>
    

    Then find the files that contain the text string indicating the component in question, in this case, c:myCmp:

    $ grep c:myCmp -R .
    ./aura/myApp/myApp.app:    <c:myCmp />
    

    Assuming that I haven't commented that section out, this would show that myCmp is being used in myApp.

    I would imagine most of the IDE's out there would provide a similar type of search function.


    Another option, if you know for sure the component is being referenced, would be to attempt to delete the component and look at the resulting errors.

    For example, a deployment with a destructiveChanges.xml file that attempted to delete the myCmp lightning component failed because the component was being referenced by myApp:

    Deployment error

    And you don't need to use the metadata api for this trick either, an attempt to delete a referenced component in the developer console will also show the error:

    enter image description here