Today We are going to Create a Model popup for Create a Account Record With Spinner .
Modals/Popup Box are used to display content in a layer above the app. This paradigm is used in cases such as the creation or editing of a record, as well as various types of messaging and wizards
Step :- 1 Create an Apex Class
Apex Class
public class AccountHandler {
@AuraEnabled
public static boolean CreateAccount (String Name , String Phone, String accountNuber, Decimal annualRevenue){
Account acc = new Account();
acc.Name = Name;
acc.Phone = phone;
acc.AccountNumber = accountNuber;
acc.AnnualRevenue = annualRevenue;
try{
insert acc;
return true;
} catch(Exception e){
return false;
}
}
}
Step 2:- Create a Lighting Component.
Lightning Component .cmp
Modal/PopUp Box
Lightning Component .JS
({
openModel: function(component, event, helper) {
component.set("v.isModalOpen", true);
},
closeModel: function(component, event, helper) {
component.set("v.isModalOpen", false);
},
submitDetails: function(component, event, helper) {
component.set("v.spinner", true);
var name = component.find("name").get("v.value");
var phone = component.find("phone").get("v.value");
var anualrevenue = component.find("anualrevenue").get("v.value");
var accountnumber = component.find("accnumber").get("v.value");
var action = component.get("c.CreateAccount");
action.setParams({ Name : name , Phone:phone, accountNuber:accountnumber,annualRevenue:anualrevenue });
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.response", response.getReturnValue());
if(response.getReturnValue() == true){
component.set("v.spinner", false);
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
title : 'Success',
message: 'Record has been Created Successfully',
duration:' 5000',
key: 'info_alt',
type: 'success',
mode: 'pester'
});
toastEvent.fire();
component.set("v.isModalOpen", false);
}
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
$A.enqueueAction(action);
},
})
Output :-
