How do we restrict an aura component to be used in the record pages of only for particular Sobjects?

Why restrict an Aura component to specific record pages?

Restricting an Aura component to specific sObjects improves user experience, reduces clutter in the Lightning App Builder, and enforces correct usage patterns. Instead of making the component available on every record page, you can limit exposure to only the objects where the component makes sense (for example, Account and Contact).

Where to configure the restriction

For Aura components, object-level availability is configured in the component’s metadata file (the *-meta.xml file — the same file that declares isExposed and targets). You add a <targetConfig> block for the lightning__RecordPage target and list the supported objects there.

Example: Restrict to Account and Contact record pages

<?xml version="1.0" encoding="UTF-8"?>

    <apiVersion>56.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordPage</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage">
            <objects>
                <object>Account</object>
                <object>Contact</object>
            </objects>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>

Notes and best practices

– The metadata file shown above is typically named yourComponentName.cmp-meta.xml for Aura bundles (or yourComponentName.js-meta.xml for LWC). For Aura, ensure you update the component bundle’s metadata file that accompanies the component.

– Use exact API names for objects (e.g., Account, Custom_Object__c).

– You can include as many <object> entries as needed. If you omit <objects> entirely under the lightning__RecordPage targetConfig, the component remains available on all record pages.

– After updating the metadata, deploy the change (via SFDX, Metadata API, or your CI/CD) and clear cache or refresh the Lightning App Builder; the availability will reflect the change.

Troubleshooting

– If the component still appears for other objects, confirm you edited the correct metadata file and that the component bundle was deployed successfully.

– For managed packages, remember namespace prefixes when referencing custom objects (e.g., ns__Custom__c).

Alternative: Programmatic guard in component

When metadata-level restriction isn’t possible or you want runtime guardrails, you can programmatically detect the sObject in the component and hide or show UI accordingly. This is not a replacement for metadata-level restriction but a useful supplement:

// Example (Aura controller)
doInit: function(component, event, helper) {
    var sobjectName = component.get("v.pageReference").attributes.objectApiName;
    var allowed = ['Account','Contact'];
    component.set('v.isAllowed', allowed.indexOf(sobjectName) !== -1);
}

Combine both: metadata-level restriction for Builder UX and a runtime check for safety.

Keywords

Aura component, lightning__RecordPage, targetConfig, sObject restriction, component metadata, Salesforce Lightning App Builder