Newer Version Available

This content describes an older version of this product. View Latest

Controlling Access

The framework enables you to control access to your applications, interfaces, components, attributes, and events via the access system attribute. The access system attribute indicates whether the resource can be used outside of its own namespace.

Use the access system attribute on these tags:

  • aura:application
  • aura:interface
  • aura:component
  • aura:attribute
  • aura:event

Access Values

You can specify these values for the access system attribute.

private
Available within the component, app, interface, or event and can’t be referenced externally. This value can only be used for aura:attribute.
public
Available within the same namespace. This is the default access value.
global
Available in all namespaces.

Mark your resources with access="global" to make the resource usable outside of your own org; for example, if you want the resource to be usable in an installed package or by a Lightning App Builder user or a Community Builder user in another org.

Note

Example

This sample component has global access.

1<aura:component access="global">
2    ...
3</aura:component>

Access Violations

If your code accesses a resource, such as a component or attribute, that doesn’t have an access system attribute allowing you to access it, you see a warning in your browser console if you enabled debug mode.

Anatomy of an Access Check Warning

This is a sample access check warning message in the browser console for an access violation.

1WARNING:  Access  Check  Failed ! ComponentService.getDef():'markup://c:targetComponent' is not visible to 'undefined'.

A warning message has four parts:

  1. The context (who is trying to access the resource). In our example, this is undefined.
  2. The target (the resource being accessed). In our example, this is markup://c:targetComponent.
  3. The type of failure. In our example, this is not visible.
  4. The code that triggered the failure. This is usually a class method. In our example, this is ComponentService.getDef(), which means that the target definition (component) was not accessible. A definition describes metadata for a resource, such as a component.

Fixing Access Check Warnings

You can fix any access check warnings using one or more of these techniques.

  • Add appropriate access system attributes to the resources that you own.
  • Remove references in your code to resources that aren’t available.
  • Ensure that any attribute that you’re accessing exists and you’re using the correct case-sensitive spelling.

    Accessing an undefined attribute or a private attribute triggers the same access violation message because the access context doesn’t know whether the attribute is undefined or private.

  • Use $A.getCallback() to wrap code that accesses a component outside the normal rerendering lifecycle, such as in a setTimeout() or setInterval() call or in an ES6 Promise.

    $A.getCallback() preserves the current execution context and grants the correct access level to the asynchronous code. Otherwise, the framework loses context and allows access only to global resources.