I am having a lightning component that uses the Lightning Data services. The component is like below which has a button which when clicking on it changes the case status to Closed.
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="loaded" type="Boolean" default="false" />
<lightning:spinner variant="brand" alternativeText="Loading..." class="{!(v.loaded? 'slds-show': 'slds-hide')}" />
<lightning:recordEditForm aura:id="form"
objectApiName="Case"
recordId="{!v.recordId}"
onsubmit="{!c.handleSubmit}"
onerror="{!c.handleError}"
onsuccess="{!c.handleSuccess}">
<!--<lightning:spinner aura:id="spinner" variant="brand" /> -->
<lightning:inputField aura:id="statusInput" fieldName="Status" class="slds-hide" />
<lightning:button variant="brand" type="submit" label="Close Case(LDS)" />
</lightning:recordEditForm>
</aura:component>
And controller
({
handleSubmit: function(component, event, helper) {
component.set('v.loaded',true);
event.preventDefault();
var fields = event.getParam('fields');
fields.Status = 'Closed';
console.log(JSON.stringify(fields));
component.find('form').submit(fields);
},
handleError: function(component, event, helper) {
component.set('v.loaded',false);
$A.get("e.force:showToast")
.setParams({
type: 'error',
mode: 'pester',
message: 'Case cannot be closed, please verify the required fields like Category are filled !!' }).fire();
},
handleSuccess: function(component, event, helper) {
component.set('v.loaded',false);
$A.get("e.force:showToast")
.setParams({
type: 'success',
message: 'Case is closed!',
mode: 'pester'
})
.fire();
}
})
I am currently in the handleError hard coding the error message but I am trying to get the errors from the Validation/ if something goes wrong instead of hard coding the errors. I tried to get the error
var error = event.getParams();
// Get the error message
var errorMessage = event.getParam("message");
and give it in the message it just gives the generic error message in the toast like
instead I should be getting the validation error
A Category is required to close the case.
How to get the Validation errors in to the lightning component from the Lightning Data Services.