You need to sign in to do that
Don't have an account?

issue in using base utility helper method
Hello
I am trying to understand how to use base utility helper method in lighting component.
This page has an error. You might just need to refresh it. Action failed: etaPrime:CallApexclassCmpBase$controller$Condata [helper.callServer is not a function] Failing descriptor: {etaPrime:CallApexclassCmpBase$controller$Condata}
I am not able to figure out what is causing the issue,
Please help.
smita
I am trying to understand how to use base utility helper method in lighting component.
Base.cmp -------- <aura:component abstract="true"> {!v.body} </aura:component> BaseHelper.js -------------- ({ callServer : function(component,method,callback,params) { var action = component.get(method); if (params) { action.setParams(params); } action.setCallback(this,function(response) { var state = response.getState(); if (state === "SUCCESS") { // pass returned value to callback function callback.call(this,response.getReturnValue()); } else if (state === "ERROR") { // generic error handler var errors = response.getError(); if (errors) { console.log("Errors", errors); if (errors[0] && errors[0].message) { throw new Error("Error" + errors[0].message); } } else { throw new Error("Unknown Error"); } } }); $A.enqueueAction(action); } }) ApexController.axpc ------------------- public with sharing class ApexController { @AuraEnabled public static List<Contact> getContacts() { List<Contact> contacts = [select Id, Name, MailingStreet, Phone, Email FROM Contact]; return contacts; } } CallApexClassCmpBase.cmp ------------------------ <aura:component controller="ApexController"> <lightning:card title="Bring Contact data"> <aura:set attribute="actions"> <lightning:button label="Contact Data" onclick="{!c.Condata}" /> </aura:set> </lightning:card> </aura:component> In the controller.js of the above component ({ Condata : function(component,event,helper) { helper.callServer( component, "c.getContacts", function(response) { console.log('Contacts data'+JSON.stringify(response)); } ); } }) <aura:application extends="force:slds"> <c:CallApexClassCmpBase/> </aura:application>when I preview this I am getting an error as below:
This page has an error. You might just need to refresh it. Action failed: etaPrime:CallApexclassCmpBase$controller$Condata [helper.callServer is not a function] Failing descriptor: {etaPrime:CallApexclassCmpBase$controller$Condata}
I am not able to figure out what is causing the issue,
Please help.
smita
Try below code and let me know if this help !
Thanks
Shivdeep
All Answers
You are passing 4 parameter in callServer helper method but in js controller you passed only 3.
Dont try to pass "function(response) { console.log('Contacts data'+JSON.stringify(response)); }" directly on helper method.
Thanks
Could you let me know how to call the helper method in the js controller?
thanks
Try below code and let me know if this help !
Thanks
Shivdeep