Lightning Components Actions Override

Introduction:-

In this blog, I am going to show how to override the standard action for the lightning experience by using lightning component. To override the standard action with the lightning component you need to implement lightning:actionOverride interface. You can override the View, New, Edit, and Tab standard actions on most standard and all custom components. Overriding standard actions allows you to customize your org using Lightning components, including completely customizing the way you view, create, and edit records.There are six standard actions available on most standard and all custom objects: Tab, List, View, Edit, New, and Delete.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.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 the Salesforce app, and so on.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.

New Action Override

Create a new lightning component with the below code
<aura:component implements="lightning:actionOverride,force:hasRecordId,force:hasSObjectName">
    <lightning:recordEditForm aura:id="recordEditForm" 
                              objectApiName="Opportunity">
        <lightning:messages />
        <lightning:inputField fieldName="Name" />
        <lightning:inputField fieldName="Amount" />
        
        <lightning:inputField fieldName="CloseDate" />
        <lightning:inputField fieldName="Description" />
        <lightning:inputField fieldName="StageName" />
        <lightning:inputField fieldName="Probability" />
        <lightning:inputField fieldName="Type" />
        <lightning:inputField fieldName="LeadSource" />
        
        <lightning:inputField fieldName="CurrentGenerators__c" />
        <lightning:inputField fieldName="TrackingNumber__c" />
        
        
        <lightning:button class="slds-m-top_small" type="submit" label="Create new" />
    </lightning:recordEditForm>
    
</aura:component>

Go to object manager and override the new  button action as shown below 

View Action Override

Crate a new lightning component with below code

<aura:component implements="lightning:actionOverride,force:hasRecordId,force:hasSObjectName">
    
    <lightning:recordViewForm recordId="{!v.recordId}" objectApiName="Opportunity">
        <div class="slds-box">
            <lightning:outputField fieldName="Name" />
            <lightning:outputField fieldName="Amount" />
            <lightning:outputField fieldName="CloseDate" />
            <lightning:outputField fieldName="Description" />
            <lightning:outputField fieldName="ExpectedRevenue" />
            <lightning:outputField fieldName="StageName" />
            <lightning:outputField fieldName="Probability" />
            <lightning:outputField fieldName="Type" />
            <lightning:outputField fieldName="CurrentGenerators__c" />
            <lightning:outputField fieldName="TrackingNumber__c" />
            
        </div>
    </lightning:recordViewForm>
    
</aura:component>

Override the view action as shown below

Override Edit Action

Create a new Lightning component with below code

<aura:component implements="lightning:actionOverride,force:hasRecordId,force:hasSObjectName">
    
    <lightning:recordEditForm recordId="{!v.recordId}" objectApiName="Opportunity">
        <lightning:messages />
        
        <lightning:inputField fieldName="Name" />
        <lightning:inputField fieldName="Amount" />
        <lightning:inputField fieldName="CloseDate" />
        <lightning:inputField fieldName="Description" />
        <lightning:inputField fieldName="ExpectedRevenue" />
        <lightning:inputField fieldName="StageName" />
        <lightning:inputField fieldName="Probability" />
        <lightning:inputField fieldName="Type" />
        
        <lightning:button class="slds-m-top_small" variant="brand" type="submit" name="update" label="Update" />
    </lightning:recordEditForm>
</aura:component>

Override the edit action as shown below

 In this example, i used the lightning:recordEditForm and lightning:recordViewForm components to wrap the form for edit and view modes.