You need to sign in to do that
Don't have an account?

How to insert Record in Location Object in Salesforce Lightning Component
When i going to create a Record in Location (Standard Object) iam not getting values from Component to Js (Controller).Can any one plz Suggest me.
Cmp:
<aura:component>
<aura:attribute name="newLocation" type="Location" default="{'sobjectType': 'Location'}"/>
<lightning:input label="Location Name" required="true" value="{!v.newLocation.Name}"/>
<lightning:select label="Location Type" value="{!v.newLocation.LocationType}">
<option value="">--None--</option>
<aura:iteration items="{!v.locationTypeValues}" var="item">
<option value="{!item}" selected="selected">{!item}</option>
</aura:iteration>
</lightning:select>
<lightning:input label="Street Name" value="{!v.newLocation.Street_Name__c}"/>
<lightning:input label="City" value="{!v.newLocation.City__c}"/>
<lightning:input label="State" value="{!v.newLocation.State__c}"/>
<lightning:input label="Zip" value="{!v.newLocation.Zip__c}"/>
</aura:component>
Controller:
var newLocation = component.get("v.newLocation");
alert('newLocation--'+newLocation);
var action = component.get("c.createRecord");
action.setParams({
newLocation : newLocation
});
action.setCallback(this,function(response){
var state = response.getState();
// alert('state--'+state);
if(state === "SUCCESS"){
var recId = response.getReturnValue();
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"message": "Record created Successfully.",
"type": "success"
});
toastEvent.fire();
$A.get('e.force:refreshView').fire();
} else if(state == "ERROR"){
//alert('Error in calling server side action');
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"message": 'Error in calling server side action',
"type": "Error"
});
toastEvent.fire();
}
});
$A.enqueueAction(action);
}
Apex Class:
@AuraEnabled
Public Static void createRecord(List<Schema.Location> newLocation)
{
System.debug('newLocation----'+newLocation);
if(newLocation !=null){
insert newLocation;
}
}
Cmp:
<aura:component>
<aura:attribute name="newLocation" type="Location" default="{'sobjectType': 'Location'}"/>
<lightning:input label="Location Name" required="true" value="{!v.newLocation.Name}"/>
<lightning:select label="Location Type" value="{!v.newLocation.LocationType}">
<option value="">--None--</option>
<aura:iteration items="{!v.locationTypeValues}" var="item">
<option value="{!item}" selected="selected">{!item}</option>
</aura:iteration>
</lightning:select>
<lightning:input label="Street Name" value="{!v.newLocation.Street_Name__c}"/>
<lightning:input label="City" value="{!v.newLocation.City__c}"/>
<lightning:input label="State" value="{!v.newLocation.State__c}"/>
<lightning:input label="Zip" value="{!v.newLocation.Zip__c}"/>
</aura:component>
Controller:
var newLocation = component.get("v.newLocation");
alert('newLocation--'+newLocation);
var action = component.get("c.createRecord");
action.setParams({
newLocation : newLocation
});
action.setCallback(this,function(response){
var state = response.getState();
// alert('state--'+state);
if(state === "SUCCESS"){
var recId = response.getReturnValue();
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"message": "Record created Successfully.",
"type": "success"
});
toastEvent.fire();
$A.get('e.force:refreshView').fire();
} else if(state == "ERROR"){
//alert('Error in calling server side action');
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"message": 'Error in calling server side action',
"type": "Error"
});
toastEvent.fire();
}
});
$A.enqueueAction(action);
}
Apex Class:
@AuraEnabled
Public Static void createRecord(List<Schema.Location> newLocation)
{
System.debug('newLocation----'+newLocation);
if(newLocation !=null){
insert newLocation;
}
}
http://www.infallibletechie.com/2017/11/forcecreaterecord-example-in-salesforce.html