You need to sign in to do that
Don't have an account?
Saroj Sahoo
lightning aura code to insert a record into SalesForce object gives an error
I am getting beow error (after providing input from UI and when I am clicking the ui press button) while trying to insert a record into SF object using Ligtning Aura. Kindly look once my code and suggest.
"This page has an error. You might just need to refresh it. Action failed: c:HDFCApp6CreateClientRecordComp$controller$CreateClient [component is not defined] Failing descriptor: {c:HDFCApp6CreateClientRecordComp$controller$CreateClient}"
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(varClient);
}
})
4. Helper:HDFCInsuranceApp6CompHelper
({
helperMethod : function() {
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') ;
}
}
}
"This page has an error. You might just need to refresh it. Action failed: c:HDFCApp6CreateClientRecordComp$controller$CreateClient [component is not defined] Failing descriptor: {c:HDFCApp6CreateClientRecordComp$controller$CreateClient}"
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(varClient);
}
})
4. Helper:HDFCInsuranceApp6CompHelper
({
helperMethod : function() {
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') ;
}
}
}
1) component was missing as a parameter and there is not default parameter known by the helper.
helper.helperMethod(component,varClient);
helperMethod : function(component,varClient) { var action = component.get("c.createRecord"); ...
2) $A.enqueueAction(action);
Now, after using your suggested paramenters, I am getting below new error
"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') ;
}
}
}
2) $A.enqueueAction(action); //
$S.enqueueAction(action);