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
vishal yadav 86vishal yadav 86 

Firing error when calling apex class on button click

ERROR :
This page has an error. You might just need to refresh it. Unable to find action 'ShowDetails' on the controller of VishalYadav: Revision_Component Failing descriptor: {VishalYadav: Revision_Component}
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi vishal,
Can you post your code here 
vishal yadav 86vishal yadav 86
COMPONENT:
<aura:component controller="Apex_Class">
    <lightning:button label="display" onclick="{!c.ShowDetails}" />
</aura:component>
CONTROLLER:
({
    ShowDetails: function(component, event, helper) {
        var action = component.get("c.InsertAccount");
        action.setParams({"Name":"Genpact","Website":"www.account.com","Phone":"903042684"});
        action.setCallback(this,function(response){
               var state = response.getState();
               if(state === 'SUCCESS')
                {
                  var result = response.getReturnValue();
                    console.log(result);
                }
              });
        $A.enqueueAction(action);
    }        
        
})
APEX CODE:
public class Apex_Class {
    @AuraEnabled
    public static string InsertAccount(string Name,string Website,string Phone){
    string result;
    try
    {
        Account acc =new Account();
        acc.name = Name;
        acc.website = Website;
        acc.phone = Phone;
        insert acc;
        result = 'record inserted successfully ==>'+acc.id;
    }catch(Exception e)
    {
        result = 'record insertion failed ==>'+e.getMessage();
    }
    return result;
  }
}
 
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi vishal,
I have gone through your code, didn't find any mistake in it.Able to execute the same code in my org without any errors.

Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.

Thanks and Regards
vishal yadav 86vishal yadav 86
Ok. Thank you!!