In this blog, I showed the code for creating records in the aura component may be this source code helps you a lot to understand the concept of the aura component.
Create an apex file (Name : createContactController.apxc)
Source Code: createContactController.apxc
public class GetContactController {
@AuraEnabled
public static void insertCon(String firstName,String lastName,String phoneNo, String emailId){
Contact con = new Contact();
con.FirstName = firstName;
con.LastName = lastName;
con.Phone = phoneNo;
con.Email = emailId;
insert con;
}
}
Create an Aura component (Name : createContactCMP)
Source Code: createContactCMP.cmp
Source Code: createContactCMPController.js
({
createContact : function(component, event, helper){
var firstNameJs = component.find("firstName").get("v.value");
var lastNameJs = component.find("lastName").get("v.value");
var phone = component.find("phone").get("v.value");
var email = component.find("email").get("v.value");
var action = component.get("c.insertCon");
action.setParams({'firstName' : firstNameJs, 'lastName' : lastNameJs, 'phoneNo' : phone, 'emailId' : email});
action.setCallback(this,function(response){
if(response.getState() == 'SUCCESS'){
alert('Record Inserted!');
}
});
$A.enqueueAction(action);
}
})
Create a lightning application (Name: CreateContactApp)
Source Code: CreateContactApp.app