You need to sign in to do that
Don't have an account?
Harshal Katole 7
save record in database
getting error : This page has an error. You might just need to refresh it. Action failed: c:LightningHotelManCompo$controller$doSave [component is not defined] Failing descriptor: {c:LightningHotelManCompo$controller$doSave}
application :
<aura:application extends="force:slds" >
<c:LightningHotelManCompo/>
</aura:application>
================================
component
<aura:component controller="LightningHotelManApex"
implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
access="global" >
<aura:attribute name="Guesthotel" type="Guest_Master__c" default="{'sObjectType':'Guest_Master__c',
'Guest_First_Name__c':'',
'Guest_Last_Name__c':'',
'Guest_Phone__c':'',
'Guest_Email__c':'',
'Number_of_Adults_12_yrs__c':'',
'Number_of_Children_0_12_yrs__c':'',
'Check_in_Date__c':'',
'Check_Out_Date__c':'',
'City_of_Hotel__c':'',
'Preferred_Hotel_Type__c':''}"/>
<div>
<div class="slds-card">
<div class="slds-p-around_medium">Please Enter Details</div>
</div>
</div>
<div class="Container-fluid">
<div class="form-group">
<label> First Name </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Guest_First_Name__c}"/>
</div>
<div class="form-group">
<label> Last Name </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Guest_Last_Name__c}"/>
</div>
<div class="form-group">
<label> Phone </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Guest_Phone__c}"/>
</div>
<div class="form-group">
<label> Email </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Guest_Email__c}"/>
</div>
<div class="form-group">
<label> Number of Adults(12+ yrs) </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Number_of_Adults_12_yrs__c}"/>
</div>
<div class="form-group">
<label> Number of Adults(0-12 yrs) </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Number_of_Children_0_12_yrs__c}"/>
</div>
<div class="form-group">
<label> Check in Date </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Check_in_Date__c}"/>
</div>
<div class="form-group">
<label> Check out Date </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Check_Out_Date__c}"/>
</div>
<div class="form-group">
<label> City of Hotel </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.City_of_Hotel__c}"/>
</div>
<div class="form-group">
<label> Prferred Hotel Type </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Preferred_Hotel_Type__c}"/>
</div>
</div>
<div class="col-md-4 text-center">
<ui:button class="btn btn-default" press="{!c.doSave}"> Save </ui:button>
</div>
</aura:component>
=============================================
controller
({
doSave : function(component, event, helper) {
console.log('create records');
helper.helperMethodGuest(component);
}
})
==========================================
helper
({
helperMethodGuest : function() {
console.log('create records in helper ');
var varGuest = component.get("v.Guesthotel");
var action = component.get("c.saveRecord");
action.setParams({
"guest" : varGuest
});
action.setCallback(this,function(response){
var state = response.getState();
if(state =="SUCCESSS"){
var newEmptyGuest = {'sObjectType':'Guest_Master__c',
'Guest_First_Name__c':'',
'Guest_Last_Name__c':'',
'Guest_Phone__c':'',
'Guest_Email__c':'',
'Number_of_Adults_12_yrs__c':'',
'Number_of_Children_0_12_yrs__c':'',
'Check_in_Date__c':'',
'Check_Out_Date__c':'',
'City_of_Hotel__c':'',
'Preferred_Hotel_Type__c':''};
component.set("v.Guesthotel",newEmptyGuest);
alert('Record is create succesfully');
}else if(state=="ERROR"){
alert('Error is clling server side action');
var ErrorDetails =response.getError();
alert('Reason of error ='+ErrorDetails[0].message);
}
});
$A.enqueueAction(action);
}
})
===================================
apex class
public class LightningHotelManApex {
@AuraEnabled
public static void saveRecord(Guest_Master__c guest){
try{
system.debug(' guest record ::'+guest);
if(guest != null){
insert guest;
}
}catch(Exception ex){
}
}
}
application :
<aura:application extends="force:slds" >
<c:LightningHotelManCompo/>
</aura:application>
================================
component
<aura:component controller="LightningHotelManApex"
implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
access="global" >
<aura:attribute name="Guesthotel" type="Guest_Master__c" default="{'sObjectType':'Guest_Master__c',
'Guest_First_Name__c':'',
'Guest_Last_Name__c':'',
'Guest_Phone__c':'',
'Guest_Email__c':'',
'Number_of_Adults_12_yrs__c':'',
'Number_of_Children_0_12_yrs__c':'',
'Check_in_Date__c':'',
'Check_Out_Date__c':'',
'City_of_Hotel__c':'',
'Preferred_Hotel_Type__c':''}"/>
<div>
<div class="slds-card">
<div class="slds-p-around_medium">Please Enter Details</div>
</div>
</div>
<div class="Container-fluid">
<div class="form-group">
<label> First Name </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Guest_First_Name__c}"/>
</div>
<div class="form-group">
<label> Last Name </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Guest_Last_Name__c}"/>
</div>
<div class="form-group">
<label> Phone </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Guest_Phone__c}"/>
</div>
<div class="form-group">
<label> Email </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Guest_Email__c}"/>
</div>
<div class="form-group">
<label> Number of Adults(12+ yrs) </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Number_of_Adults_12_yrs__c}"/>
</div>
<div class="form-group">
<label> Number of Adults(0-12 yrs) </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Number_of_Children_0_12_yrs__c}"/>
</div>
<div class="form-group">
<label> Check in Date </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Check_in_Date__c}"/>
</div>
<div class="form-group">
<label> Check out Date </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Check_Out_Date__c}"/>
</div>
<div class="form-group">
<label> City of Hotel </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.City_of_Hotel__c}"/>
</div>
<div class="form-group">
<label> Prferred Hotel Type </label>
<ui:inputText Class="form-control" value="{!v.Guesthotel.Preferred_Hotel_Type__c}"/>
</div>
</div>
<div class="col-md-4 text-center">
<ui:button class="btn btn-default" press="{!c.doSave}"> Save </ui:button>
</div>
</aura:component>
=============================================
controller
({
doSave : function(component, event, helper) {
console.log('create records');
helper.helperMethodGuest(component);
}
})
==========================================
helper
({
helperMethodGuest : function() {
console.log('create records in helper ');
var varGuest = component.get("v.Guesthotel");
var action = component.get("c.saveRecord");
action.setParams({
"guest" : varGuest
});
action.setCallback(this,function(response){
var state = response.getState();
if(state =="SUCCESSS"){
var newEmptyGuest = {'sObjectType':'Guest_Master__c',
'Guest_First_Name__c':'',
'Guest_Last_Name__c':'',
'Guest_Phone__c':'',
'Guest_Email__c':'',
'Number_of_Adults_12_yrs__c':'',
'Number_of_Children_0_12_yrs__c':'',
'Check_in_Date__c':'',
'Check_Out_Date__c':'',
'City_of_Hotel__c':'',
'Preferred_Hotel_Type__c':''};
component.set("v.Guesthotel",newEmptyGuest);
alert('Record is create succesfully');
}else if(state=="ERROR"){
alert('Error is clling server side action');
var ErrorDetails =response.getError();
alert('Reason of error ='+ErrorDetails[0].message);
}
});
$A.enqueueAction(action);
}
})
===================================
apex class
public class LightningHotelManApex {
@AuraEnabled
public static void saveRecord(Guest_Master__c guest){
try{
system.debug(' guest record ::'+guest);
if(guest != null){
insert guest;
}
}catch(Exception ex){
}
}
}
you have forgot to write component into helper method.Replace your helper Method with below.
helperMethodGuest : function(component) {
let me know if it helps you and don't forget to mark it as best answer.
Thank you
All Answers
you have forgot to write component into helper method.Replace your helper Method with below.
helperMethodGuest : function(component) {
let me know if it helps you and don't forget to mark it as best answer.
Thank you