Greetings of the day1

I'm stuck in a problem where my onclick on Lightning button is not invoking javascript function.

Functionality: I have created a quick action on account labled as "Convert to Account". Once a user is clicking the button a dilog box will appear and it'll ask to continue Yes or No. If a user clicks yes then the contact gets deleted and new account is created and new account record gets created. If a user clicks No the transaction gets cancelled.

Please refer the below code:


<aura:component controller="Convert_Contact_to_Account" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
   <div class="c-container">
        <lightning:layout verticalAlign="center" class="x-large">
            <lightning:layoutItem flexibility="auto" padding="around-small">
                <div class="slds-align_absolute-center" style="height:5rem">
                    <h1> <b>Would you like to Convert this Contact to Account?</b></h1>
                <div class="slds-align_absolute-center" style="height:5rem">
                    <lightning:button variant="brand" label="Yes" title="Yes" onclick="{!c.Convert}" />
                    <lightning:button variant="brand" label="No" title="No" onclick="{!c.Cancel}" />


    Convert : function(component, event, helper) {
        let recId = component.get("v.recordId");
        var action = component.get("c.Convert_Contact_to_Account");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                let accid= response.getReturnValue();//Returns the inserted id from apex
                if(accid != ''){
                    var toastEvent = $A.get("e.force:showToast");
                        "title": "Success!!",
                        "message": "Account Creation Successfull!",
                else if(state == "ERROR"){
                    var errors = response.getError();                      
                var navEvt = $A.get("e.force:navigateToSObject");
                    "slideDevName": "Detail"
        // Send action off to be executed
        Cancel : function(component,event,helper){

Apex class:

public class Convert_Contact_to_Account {
    public static String convertToAccount(String recId){
        Contact c=[select id,LastName from Contact where id=:recId];
        account a=new account();
        insert a;
        delete c;
        return a.Id;

Line <lightning:button variant="brand" label="Yes" title="Yes" onclick="{!c.Convert}" /> is not invoking c.Convert function.

If anyone can review the code especially the javascript that'll be very helpful.Any lead will be appreciated.

Thanks & Regards, Sumit

  • When you say that the button isn't invoking your Convert method, do you mean the body of Convert_Contact_to_AccountController.Convert() is never entered? I see no issues with the code up to that point, but your action will fail. The name of the method in your Apex controller is convertToAccount - it is not Convert_Contact_to_Account. Does your Console.log('HIiiiiiiiiiiiiiiiiiii'); get logged? Look at adding a debugger; statement at the start of Convert so you can walk through the code in your browser developer console.
    – nbrown
    Jan 29, 2021 at 15:45
  • Hi, I've added a console.log() at starting to print HIiii but even that is not getting logged. And moreover I've changed the code to call aura enabled method instead of class. But still the function on yes button is not invoked. Jan 29, 2021 at 16:40

1 Answer 1


Issue in your code, you are calling apex class, which is wrong.

var action = component.get("c.Convert_Contact_to_Account");

This should be auraEnabled Method name

var action = component.get("c.convertToAccount");
  • Hi Sarvesh I've modified the code to call aura enabled method instead of apex class still button is not invoking the JavaScript function. Moreover at least it should print hi on console. Even that is not getting printed. Jan 29, 2021 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .