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
Harshal Katole 7Harshal 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){
            
        }
    }

}
Best Answer chosen by Harshal Katole 7
ravi soniravi soni
hy Harshal,
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

ravi soniravi soni
hy Harshal,
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
 
This was selected as the best answer
Harshal Katole 7Harshal Katole 7
@veersoni ohhh sorry i forgot to mention.....can you guiide me how to add date field record and picklist as well