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
Sumit Kumar SouravSumit Kumar Sourav 

Lightning button is not invoking javascript function in aura component

Sumit Kumar SouravSumit Kumar Sourav
Hello Everyone,

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,
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Sumit, 

Try this out, 

var action = component.get("c.Convert_Contact_to_Account");
var action = component.get("c.convertToAccount");
Apart from that, please try to use let instead of var, though this using var is not the root cause here. You need to call the Apex method name instead of the Apex class name. 


Sumit Kumar SouravSumit Kumar Sourav
Hi Prosenjoy,
Thank you so much for your instant reply. I've made the changes as you suggested to call aura enabled method instead of class. But still it's yes button not invoking the convert method.
II'll be very helpful if you could identify the root cause.

Warm Regards,