You need to sign in to do that
Don't have an account?
ashwini gattu
Action failed: c:TeacherAppCompo$controller$createClient [helper is not defined]
Hi ,
I tried to create my first lightning application but i get the folowing error.
Below is my code
Application
<aura:application extends="force:slds" >
<c:TeacherAppCompo/>
</aura:application>
Component
<aura:component controller='TeacherCreateRecord' >
<aura:attribute name="client" type="Teacher__c" default="{'sObjectType':'Teacher__c','Name' : '' }" />
<ui:inputtext label="Enter Teacher Name" value="{!v.client.Name}" />
<ui:button label="Submit" press="{!c.createClient}"/>
</aura:component>
Client side contoller
({
createClient : function(component, event) {
//for logs
console.log("In Client Controller");
//getting the record info from component to js
var varClient=component.get("v.client");
//validation to check of field is empty or not
if($A.util.isEmpty(varClient.Name) || $A.util.isUndefined(varClient.Name) )
{
alert('First name is required');
//return the value and function will stop
return;
}
helper.createRecord(varClient);
}
})
Helper
({
createRecord : function() {
console.log("In helper");
//calling apex function
alert('Before action');
var action = component.get("c.createTeacherRecord");
alert('Before set params function');
//set the parameters
action.setParams({
client : varClient
});
alert('Before callback function');
//set callback function
action.setCallback(this,function(a){
var response=a.getState();
if(response == "SUCCESS")
{
//Reset form and this is optional
var newrecord= {'sObjectType' : 'Teacher__c','Name':''};
component.set("v.client",newrecord);
alert('Record is Created');
}else if(response == "ERROR")
{
alert('Record is not Created');
}
});
//To enqueue all actions and let all happen one by one
$A.enqueueAction(action);
}
})
ApexClass
public with sharing class TeacherCreateRecord {
@AuraEnabled
public static void createTeacherRecord(Teacher__c client)
{
try{
System.debug('Teacher Create Record class'+ client) ;
if(client != null)
{
insert client;
}
}
catch(Exception e)
{
System.debug('Inside Apex class') ;
}
}
}
The object i have used is Teacher__c and i am trying to fetch the name which is a standard field .
I tried to create my first lightning application but i get the folowing error.
Below is my code
Application
<aura:application extends="force:slds" >
<c:TeacherAppCompo/>
</aura:application>
Component
<aura:component controller='TeacherCreateRecord' >
<aura:attribute name="client" type="Teacher__c" default="{'sObjectType':'Teacher__c','Name' : '' }" />
<ui:inputtext label="Enter Teacher Name" value="{!v.client.Name}" />
<ui:button label="Submit" press="{!c.createClient}"/>
</aura:component>
Client side contoller
({
createClient : function(component, event) {
//for logs
console.log("In Client Controller");
//getting the record info from component to js
var varClient=component.get("v.client");
//validation to check of field is empty or not
if($A.util.isEmpty(varClient.Name) || $A.util.isUndefined(varClient.Name) )
{
alert('First name is required');
//return the value and function will stop
return;
}
helper.createRecord(varClient);
}
})
Helper
({
createRecord : function() {
console.log("In helper");
//calling apex function
alert('Before action');
var action = component.get("c.createTeacherRecord");
alert('Before set params function');
//set the parameters
action.setParams({
client : varClient
});
alert('Before callback function');
//set callback function
action.setCallback(this,function(a){
var response=a.getState();
if(response == "SUCCESS")
{
//Reset form and this is optional
var newrecord= {'sObjectType' : 'Teacher__c','Name':''};
component.set("v.client",newrecord);
alert('Record is Created');
}else if(response == "ERROR")
{
alert('Record is not Created');
}
});
//To enqueue all actions and let all happen one by one
$A.enqueueAction(action);
}
})
ApexClass
public with sharing class TeacherCreateRecord {
@AuraEnabled
public static void createTeacherRecord(Teacher__c client)
{
try{
System.debug('Teacher Create Record class'+ client) ;
if(client != null)
{
insert client;
}
}
catch(Exception e)
{
System.debug('Inside Apex class') ;
}
}
}
The object i have used is Teacher__c and i am trying to fetch the name which is a standard field .
I have gone through your problem.Please try the below code.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
All Answers
It looks like the problem is that you are passing an argument when calling the Helper :
But Helper createRecord method that does not seem to accepting one. Try replacing the helper method line as follow:
Let me know if the problem still persists.
Regards
Ayush
The code works only if i dont call the helper and add all the code in the client side controller itself.
I have gone through your problem.Please try the below code.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
I kept using helper.createRecord(component, event,helper) all the while , i dint even know that we can pass the variable seperately as well.
Thankyou !!
your answer to Ashwini gattu also helped in to resolve the issue of same problem, by using helper.createRecord(component, event,helper,varClient); and createRecord : function(component, event,helper,varClient). Thank you Sachin