function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saugandh KSaugandh K 

How to call an overridden custom 'Edit' button (in Customer object )to load a lightning Component?

The current situation is like this:
When i click on the radiobutton it passes the corresponding accountId to the following function.
doUpdate: function(component,event){
        var action = component.get("c.doUpdate");
        action.setParams({req : 'test'});
        action.setCallback(this, function(response){ 
            var selectedRows = event.getParam('selectedRow');
            var navigateEvent = $A.get("e.force:editRecord");
            navigateEvent.setParams({ "recordId": selectedRow[0].Id  });
            navigateEvent.fire();
        });
         $A.enqueueAction(action);
    }

The code in the setCallback lets me popup the account edit screen successfully. The problem is that the popup loads the default recordtype layout. I am expecting the custom Lightning component to be loaded in the popup ( I could override the editbutton on customer page, but how to mimic this edit button click in code?).
 
Best Answer chosen by Saugandh K
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
You can user createComponent Method

var cType ="c:ComponentName";
        $A.createComponent(
            cType,
            {
                parentID : parentRecId,
                actionName : 'view'   // Parameter to pass on component
            },
            function(newComponent,status){
                
                if (status === "SUCCESS") 
                {
                    var content = component.find("div1");
                    content.set("v.body", newComponent);
                    
                }else
                {
                }     
            }
        );
        
   OR 
   
   Note ** -- PAFId will be auraId of Div in your lightning component 
 $Lightning.use("c:AppName", function() {
        $Lightning.createComponent("c:ComponentName",
                                   {      
                                       parentID : '{!parentRecID}',
                                       actionName : '{!actionName}'  // Parameter to pass on component
                                   },
                                   "PAFId",
                                   function(component) {
                                       console.log('comp invoked');
                                      
                                   });
    }); 
   

All Answers

Manvendra Chaturvedi 26Manvendra Chaturvedi 26
Hi Saugandh ,

Follow this trailhead , it will solve your problem

https://trailhead.salesforce.com/en/content/learn/projects/workshop-override-standard-action/override_4
Saugandh KSaugandh K
@Manvendra Chaturvedi 26 
Thankyou for the quick reply, however I know how to override the standard button to load custom lighnting conponent using lighning action. This will work when we directly click on EDIT button. But i have the requirement to do it in code. 
The sample code snipet allows me to load standard page only!!! I need this custom lighning component to be loaded.

See the below image which pops the default layout.

User-added image

When i click on EDIT manually below pops, which is expected:
User-added image
Manvendra Chaturvedi 26Manvendra Chaturvedi 26
You can user createComponent Method

var cType ="c:ComponentName";
        $A.createComponent(
            cType,
            {
                parentID : parentRecId,
                actionName : 'view'   // Parameter to pass on component
            },
            function(newComponent,status){
                
                if (status === "SUCCESS") 
                {
                    var content = component.find("div1");
                    content.set("v.body", newComponent);
                    
                }else
                {
                }     
            }
        );
        
   OR 
   
   Note ** -- PAFId will be auraId of Div in your lightning component 
 $Lightning.use("c:AppName", function() {
        $Lightning.createComponent("c:ComponentName",
                                   {      
                                       parentID : '{!parentRecID}',
                                       actionName : '{!actionName}'  // Parameter to pass on component
                                   },
                                   "PAFId",
                                   function(component) {
                                       console.log('comp invoked');
                                      
                                   });
    }); 
   
This was selected as the best answer