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
Karunat1Karunat1 

My record is not not save when i click on save button

Hi,
Here is my component. with the help of this component m trying to insert record in my Custom object Mentotr__c. But my records is nnot saving on button click
Component:
<aura:component controller="createMentor" implements="lightning:actionOverride,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="newMentor" type="Mentor__c" default="{'sobjectType': 'Mentor__c',
                                                               'Name': '',
                                                               'Email__c': '',
                                                               'Phone__c': '',
                                                               'No_of_Inters__c': '',
                                                               'No_of_Sessions__c': '',
                                                               'No_of_Sessions_Taken__c': '',
                                                               'Session__c': ''}"/>
    <!-- Create attribute to store lookup value as a sObject--> 
    <aura:attribute name="selectedLookUpRecord" type="sObject" default="{}"/>
    
    <ui:button class="slds-align_absolute-center" label="Click Me To Popup!!!" press="{!c.openmodal}"  /> 
    <div role="dialog" tabindex="-1" aria-labelledby="header43" aura:id="Modalbox" class="slds-modal slds-modal_large">
        <div class="slds-modal__container" style="width: 65%;">
            <div class="slds-modal__header">
                CREATE
            </div>
            <div class="slds-modal__content slds-p-around--medium">
                <!--FIRSTSECTION-->
                <div class="slds-p-left_xx-large slds-p-right_xx-large">
                    <div class="slds-page-header" style="padding-top: 9px; padding-bottom: 9px;, padding-right: 9px;, padding-left: 10px;">
                        <h3 style="font-size: 1rem;" title="">Intern Information</h3>
                    </div> 
                </div>    
                <div class="slds-grid slds-p-top_medium">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <lightning:input label="Name" name="myname"  /> 
                    </div>
                    <div class="slds-size_5-of-12 slds-p-left_xx-small slds-p-horizontal_x-large " >
                        <lightning:input label="Email" name="myname" /> 
                    </div>
                </div>
                <div class="slds-grid slds-p-top_x-small">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <lightning:input label="Phone" name="myname"  /> 
                    </div>
                    <div class="slds-size_5-of-12 slds-p-left_xx-small slds-p-horizontal_x-large " >
                        <c:customLookupCmp objectAPIName="Intern__c"
                                               IconName="standard:Intern__c" 
                                               selectedRecord="{!v.selectedLookUpRecord}" 
                                               label="Intern Name"/>
                    </div>
                </div>
                <div class="slds-grid slds-p-top_x-small">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <c:customLookupCmp objectAPIName="Session__c" 
                                               IconName="standard:Session__c" 
                                               selectedRecord="{!v.selectedLookUpRecord}" 
                                               label="Session Name"/> 
                    </div>
                    
                </div>
                
                <!--SECONDSECTION-->
                <div class="slds-p-left_xx-large slds-p-right_xx-large slds-p-top_medium">
                    <div class="slds-page-header" style="padding-top: 9px; padding-bottom: 9px;, padding-right: 9px;, padding-left: 10px;">
                        <h3 style="font-size: 1rem;" title="">Count Records</h3>
                    </div> 
                </div>    
                <div class="slds-grid slds-p-top_medium">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <lightning:input label="No of Interns" name="myname"  /> 
                    </div>
                    <div class="slds-size_5-of-12 slds-p-left_xx-small slds-p-horizontal_x-large " >
                        <lightning:input label="No of Sessions" name="myname" /> 
                    </div>
                </div>
                <div class="slds-grid slds-p-top_x-small">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <lightning:input label="No of Sessions Taken" name="myname"  /> 
                    </div>
                    </div>
            </div>
            <div class="slds-modal__footer">
                <ui:button label="Save" press="{!c.saveMentor}"/>
                <ui:button label="Close" press="{!c.closeModal}"/>
            </div>
        </div>
    </div>
    <div class="slds-backdrop " aura:id="Modalbackdrop"></div>   
</aura:component>
JS Controller:
({
	closeModal:function(component,event,helper){    
		var cmpTarget = component.find('Modalbox');
		var cmpBack = component.find('Modalbackdrop');
		$A.util.removeClass(cmpBack,'slds-backdrop--open');
		$A.util.removeClass(cmpTarget, 'slds-fade-in-open'); 
    	},
	openmodal:function(component,event,helper) {
		var cmpTarget = component.find('Modalbox');
		var cmpBack = component.find('Modalbackdrop');
		$A.util.addClass(cmpTarget, 'slds-fade-in-open');
		$A.util.addClass(cmpBack, 'slds-backdrop--open'); 
	},
    saveMentor: function(component, event, helper) {
        var mntr = component.get("v.newMentor");
        var action = component.get("c.CreateMentor");
        action.setParams({ 
            "mntr": mntr
        });
        action.setCallback(this, function(a) {
            var state = a.getState();
            if (state === "SUCCESS") {
               // var name = a.getReturnValue();
                document.getElementById("backGroundSectionId").style.display = "none";
                document.getElementById("newMentorSectionId").style.display = "none";
            }else if (a.getState() === "ERROR") {
                $A.log("Errors", a.getError());
            }
        });
        $A.enqueueAction(action)
    },
})

Apex Class:
public class createMentor {
    @AuraEnabled
    public static void CreateMentor(Mentor__c mntr){
        insert mntr;
    }
}
Thanks
AJAY KRISHNA RAJAY KRISHNA R
Hi,

I think you are not setting the value received from the lightning: input to your attribute newMentor. Here is an example.
 
<div class="slds-grid slds-p-top_medium">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <lightning:input label="Name" name="myname" value="{!v.newMentor.Name}" /> 
                    </div>
                    <div class="slds-size_5-of-12 slds-p-left_xx-small slds-p-horizontal_x-large " >
                        <lightning:input label="Email" name="myname" value="{!v.newMentor.Email__c}"/> 
                    </div>
                </div>
Regards 
Ajay Krishna R
 
Raj VakatiRaj Vakati
Use this markup
 
<aura:component controller="createMentor" implements="lightning:actionOverride,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="newMentor" type="Mentor__c" default="{'sobjectType': 'Mentor__c',
                                                               'Name': '',
                                                               'Email__c': '',
                                                               'Phone__c': '',
                                                               'No_of_Inters__c': '',
                                                               'No_of_Sessions__c': '',
                                                               'No_of_Sessions_Taken__c': '',
                                                               'Session__c': ''}"/>
    <!-- Create attribute to store lookup value as a sObject--> 
    <aura:attribute name="selectedLookUpRecord" type="sObject" default="{}"/>
    
    <ui:button class="slds-align_absolute-center" label="Click Me To Popup!!!" press="{!c.openmodal}"  /> 
    <div role="dialog" tabindex="-1" aria-labelledby="header43" aura:id="Modalbox" class="slds-modal slds-modal_large">
        <div class="slds-modal__container" style="width: 65%;">
            <div class="slds-modal__header">
                CREATE
            </div>
            <div class="slds-modal__content slds-p-around--medium">
                <!--FIRSTSECTION-->
                <div class="slds-p-left_xx-large slds-p-right_xx-large">
                    <div class="slds-page-header" style="padding-top: 9px; padding-bottom: 9px;, padding-right: 9px;, padding-left: 10px;">
                        <h3 style="font-size: 1rem;" title="">Intern Information</h3>
                    </div> 
                </div>    
                <div class="slds-grid slds-p-top_medium">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <lightning:input label="Name" name="myname"  value="{!v.newMentor.Name}"/> 
                    </div>
                    <div class="slds-size_5-of-12 slds-p-left_xx-small slds-p-horizontal_x-large " >
                        <lightning:input label="Email" name="myname"  value="{!v.newMentor.Email__c}"/> 
                    </div>
                </div>
                <div class="slds-grid slds-p-top_x-small">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <lightning:input label="Phone" name="myname"  value="{!v.newMentor.Phone__c}"/> 
                    </div>
                    <div class="slds-size_5-of-12 slds-p-left_xx-small slds-p-horizontal_x-large " >
                        <c:customLookupCmp objectAPIName="Intern__c"
                                               IconName="standard:Intern__c" 
                                               selectedRecord="{!v.selectedLookUpRecord}" 
                                               label="Intern Name"/>
                    </div>
                </div>
                <div class="slds-grid slds-p-top_x-small">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <c:customLookupCmp objectAPIName="Session__c" 
                                               IconName="standard:Session__c" 
                                               selectedRecord="{!v.selectedLookUpRecord}" 
                                               label="Session Name"/> 
                    </div>
                    
                </div>
                
                <!--SECONDSECTION-->
                <div class="slds-p-left_xx-large slds-p-right_xx-large slds-p-top_medium">
                    <div class="slds-page-header" style="padding-top: 9px; padding-bottom: 9px;, padding-right: 9px;, padding-left: 10px;">
                        <h3 style="font-size: 1rem;" title="">Count Records</h3>
                    </div> 
                </div>    
                <div class="slds-grid slds-p-top_medium">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <lightning:input label="No of Interns" name="myname"  value="{!v.newMentor.No_of_Inters__c}"/> 
                    </div>
                    <div class="slds-size_5-of-12 slds-p-left_xx-small slds-p-horizontal_x-large " >
                        <lightning:input label="No of Sessions" name="myname" value="{!v.newMentor.No_of_Sessions__c}"/> 
                    </div>
                </div>
                <div class="slds-grid slds-p-top_x-small">
                    <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large " >
                        <lightning:input label="No of Sessions Taken" name="myname"  value="{!v.newMentor.No_of_Sessions_Taken__c}"/> 
                    </div>
                    </div>
            </div>
            <div class="slds-modal__footer">
                <ui:button label="Save" press="{!c.saveMentor}"/>
                <ui:button label="Close" press="{!c.closeModal}"/>
            </div>
        </div>
    </div>
    <div class="slds-backdrop " aura:id="Modalbackdrop"></div>   
</aura:component>

 
Karunat1Karunat1
Raj it is not working....