Override Standard Actions with Lightning Components

At long last, you can override four of the standard actions on objects—View, New, Edit, and Tab—using Lightning components. You can override these actions on standard and custom objects. Overriding standard actions allows you to customize your org using Lightning components, including completely customizing the way you view, create, and edit records.

The ability to override standard actions has long been possible using Visualforce pages. It’s also long been a top request for Lightning components. We’re thrilled to be adding this feature, and we hope you find it just as exciting. (This isn’t just a feature, it’s an adventure.)

All of that said, there’s a lot you need to know to successfully use action overrides with Lightning components. On the surface, adding an action override that uses a Lightning component is almost exactly the same as using a Visualforce page. You simply choose a different item, and away you go. Override a standard action with a Lightning component

However, there are important differences from Visualforce in how you create Lightning components that can be used as action overrides, and significant differences in how Salesforce uses them. You’ll want to read the details thoroughly before you get started, and test carefully in your sandbox or Developer Edition org before deploying to production.

Standard Actions and Overrides Basics

There are six standard actions available on most standard and all custom objects: Tab, List, View, Edit, New, and Delete. In Salesforce Classic, these are all distinct actions.

Lightning Experience and Salesforce1 combine the Tab and List actions into one action, Object Home. However, Object Home is reached via the Tab action in Lightning Experience, and the List action in Salesforce1. In this release, you can only override the Tab action with a Lightning component, so you can’t use a component to override the List action for Salesforce1. Finally, Salesforce1 has a unique Search action (reached via Tab). (Yes, it’s a bit awkward and complicated.)

This table lists the standard actions you can override for an object as the actions are named in Setup, and the resulting action that’s overridden in the three different user experiences.
Override in Setup Salesforce Classic Lightning Experience Saleforce1
Tab object tab object home search
List object list n/a object home
View record view record home record home
Edit record edit record edit record edit
New record create record create record create
Delete record delete record delete record delete
Note

Note

  • “n/a” doesn’t mean you can’t access the standard behavior, and it doesn’t mean you can’t override the standard behavior. It means you can’t access the override. It’s the override’s functionality that’s not available.
  • There are two additional standard actions, Accept and Clone. These actions are more complex, and overriding them is an advanced project. Overriding them with Lightning components isn’t supported.

How and Where You Can Use Lightning Component Action Overrides

Lightning components can be used to override the View, New, Edit, and Tab standard actions in Lightning Experience and Salesforce1. Unlike Visualforce, overrides that use Lightning components don’t affect Salesforce Classic. That is:
  • If you override a standard action with a Visualforce page, it overrides the action in Salesforce Classic, Lightning Experience, and Salesforce1.
  • If you override a standard action with a Lightning component, it overrides the action in Lightning Experience and Salesforce1, but the standard Salesforce page is used in Salesforce Classic.

A Lightning record page for an object takes precedence over an override of the object’s View action. That is, if you override the View action for an object, and you also create and assign a Lightning record page for the object, the Lightning record page is used. The override has no effect. This is true whether the override uses a Lightning component or a Visualforce page.

Action overrides aren’t supported in Lightning console apps, and are silently ignored when invoked. If a Lightning console app user triggers an action that has been overridden, they see the standard action instead. If they trigger the same action outside of a Lightning console app, they see the overridden action. This behavior can result in an inconsistent user experience, which you should warn users about. Also ensure that you meet your data validation requirements using triggers and validation rules, rather than code that only runs in the action override. This strategy ensures that your data is valid, whether it’s changed using a standard action or an action override.

Override a Standard Action with a Lightning Component

You can override a standard action in both Salesforce Classic and Lightning Experience. While the destination is the same, the navigation paths are different.

Lightning Experience

  1. From Setup, enter object in the Quick Find box.
  2. Select Object Manager.
  3. Click the name of the object for which you want to override a standard action.
  4. Select Buttons, Links, and Actions.

Salesforce Classic

  1. From Setup, navigate to the object for which you want to override a standard action.
    • For standard objects, navigate to Build | Customize, and find the object.
    • For custom objects, navigate to Build | Create | Objects, and find the object.
  2. Click the name of the object.
  3. Scroll to the Buttons, Links, and Actions section.
Once you’re viewing the object’s Buttons, Links, and Actions list, select Edit for the action you want to override. From here, the steps are the same.
  1. For Override With, select Lightning Component Bundle.
  2. From the drop-down menu, select the name of the Lightning component to use as the action override.
  3. Click Save.
Note

Note

Users won’t see changes to action overrides until they reload Lightning Experience or Salesforce1.

Creating a Lightning Component for Use as an Action Override

Add the lightning:actionOverride interface to a Lightning component to allow it to be used as an action override in Lightning Experience or Salesforce1. Only components that implement this interface appear in the Lightning Component Bundle menu of an object action Override Properties panel.

<aura:component 
    implements="lightning:actionOverride,force:hasRecordId,force:hasSObjectName">
    
    <article class="slds-card">
      <div class="slds-card__header slds-grid">
        <header class="slds-media slds-media--center slds-has-flexi-truncate">
          <div class="slds-media__body">
            <h2><span class="slds-text-heading--small">Expense Details</span></h2>
          </div>
        </header>
        <div class="slds-no-flex">
            <lightning:button label="Edit" onclick="{!c.handleEdit}"/>
        </div>
      </div>
      <div class="slds-card__body">(expense details go here)</div>
    </article>
</aura:component>

In Lightning Experience, the standard Tab and View actions display as a page, while the standard New and Edit actions display in an overlaid panel. When used as action overrides, Lightning components that implement the lightning:actionOverride interface replace the standard behavior completely. However, overridden actions always display as a page, not as a panel. Your component displays without controls, except for the main Lightning Experience navigation bar. Your component is expected to provide a complete user interface for the action, including navigation or actions beyond the navigation bar. Component example as rendered in Lightning Experience

One important difference from Visualforce that’s worth noting is how components are added to the Lightning Component Bundle menu. The Visualforce Page menu lists pages that either use the standard controller for the specific object, or that don’t use a standard controller at all. This filtering means that the menu options vary from object to object, and offer only pages that are specific to the object, or completely generic.

The Lightning Component Bundle menu includes every component that implements the lightning:actionOverride interface. A component that implements lightning:actionOverride can’t restrict an admin to overriding only certain actions, or only for certain objects. We recommend that your organization adopt processes and component naming conventions to ensure that components are used to override only the intended actions on intended objects. Even so, it’s your responsibility as the component developer to ensure that components that implement the lightning:actionOverride interface gracefully respond to being used with any action on any object.

Access Current Record Details

Components you plan to use as action overrides usually need details about the object type they’re working with, and often the ID of the current record. Your component can implement the following interfaces to access those object and record details.

force:hasRecordId

Add the force:hasRecordId interface to a Lightning component to enable the component to be assigned the ID of the current record. The current record ID is useful if the component is used on a Lightning record page, as an object-specific custom action or action override in Lightning Experience or Salesforce1, and so on.

force:hasSObjectName

Add the force:hasSObjectName interface to a Lightning component to enable the component to be assigned the API name of current record’s sObject type. The sObject name is useful if the component can be used with records of different sObject types, and needs to adapt to the specific type of the current record.