You need to sign in to do that
Don't have an account?
vishal 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}
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}
Can you post your code here
<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;
}
}
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