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
Saroj SahooSaroj Sahoo 

lightning aura-Getting an error while trying to insert a record into SF object.

 I am getting below error while trying to insert a record into SF object using lightning Aura. Kidly look once and suggest.

"This page has an error. You might just need to refresh it. Action failed: c:HDFCApp6CreateClientRecordComp$controller$CreateClient [$S is not defined] Failing descriptor: {c:HDFCApp6CreateClientRecordComp$controller$CreateClient}"

Please look once below modified code and kindly suggest.

1. App: HDFCInsuranceApp6

<aura:application extends="force:slds">
<c:HDFCApp6CreateClientRecordComp/>
</aura:application>

2. Comp:HDFCApp6CreateClientRecordComp



<aura:component controller="HDFCCreateClientRecord"
                implements="FlexiPage:availableForAllPageTypes"
                access="global">
<aura:attribute name="AttrClient" type="SS_HDFC_Customer_Detail__C"
default="{'sobjectType':'SS_HDFC_Customer_Detail__C',
'First_Name__c':'',
'Last_Name__c':'',
'Email__C':'',
'Monthly_Salary__c':''
}"/>

<div class="slds-page-header">
<div class="slds-media__body">
<h1 class="slds-page-header__title slds-truncate slds-align-middle" > Welcome to HDFC Insurance </h1>
<h2 class="slds-text-body_small slds-line-height_reset"> Please enter client details </h2>
</div></div>

<div class="container-fluid">
<h3> please enter the candidate information : </h3>
   
<div class="form-group">
<label>First Name : </label>
<ui:inputText class="form-control" value="{!v.AttrClient.First_Name__c}" />
</div>
<div class="form-group">
<label>Last Name : </label>
<ui:inputText class="form-control" value="{!v.AttrClient.Last_Name__c}" />
</div>
<div class="form-group">
<label>Email Address : </label>
<ui:inputText class="form-control" value="{!v.AttrClient.Email__c}" />
</div>
<div class="form-group">
<label>Monthly Salary: </label>
<ui:inputText class="form-control" value="{!v.AttrClient.Monthly_Salary__c}" />
</div>
</div>

<div class="col-md-4 text-center">
<ui:button class="btn btn-default" press="{!c.CreateClient}">Create</ui:button>
</div>
</aura:component>

  3. Client Side Controller:  

({

CreateClient : function(component, event, helper){
console.log('In Create record function');
var varClient=component.get("v.AttrClient");
if($A.util.isEmpty(varClient.First_Name__c) || $A.util.isUndefined(varClient.First_Name__c)){
alert('First Name is required');
return; }
if($A.util.isEmpty(varClient.Last_Name__c) || $A.util.isUndefined(varClient.Last_Name__c))
{alert('Last Name is required');
return;
}

    helper.helperMethod(component,varClient);
}

})

4. Helper:HDFCInsuranceApp6CompHelper

({

helperMethod : function(component,varClient) {

var action = component.get("c.createRecord");
action.setParams({client : varClient});
action.setCallback(this,function(response){
var state=response.getState();
if(state == "SUCCESS"){


var newEmptyClientRec={'sobjectType':'SS_HDFC_Customer_Detail__C',
'First_name__c':'',
'Last_name__c':'',
'Email__C':'',
'Monthly_Salary__c':''};
component.set("v.AttrClient",newEmptyClientRec);
alert('Record is created Successfully');

} else if(state == "ERROR"){
alert('Errpr om ca;;omg server side action');}

});

$S.enqueueAction(action);
}
})

5. Server side controller ( Apex):HDFCCreateClientRecord

public with Sharing class HDFCCreateClientRecord {

    @AuraEnabled
public static void createRecord (SS_HDFC_Customer_Detail__C client){

try{

system.debug('HDFC record'+ client);
if(client !=null){
insert client;

}
} catch(Exception ex){
System.debug('Inside Apex class') ;  
}
}

David Zhu 🔥David Zhu 🔥
You may change the line $S.enqueueAction(action); to

$A.enqueueAction(action);