8

There seems to be an issue with the error handling on lightning:recordForm, and some real limitations on lightning:recordEditForm. Trying to determine if this is a bug or a mistake on my part.

Example - create this component:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:attribute name="fieldsList" type="String[]" default="['FirstName', 'LastName', 'Phone', 'Email']"/>

    <fieldset class="slds-box slds-theme--default slds-container--large">
        <legend id="accountsearchform"
                class="slds-text-heading--medium slds-p-vertical--medium">New Contact
        </legend>

        <lightning:messages aura:id="emessages" />

        <lightning:recordForm
                aura:id="newcontactform"
                objectApiName="Contact"
                fields="{!v.fieldsList}"
                columns="2"
                mode="edit"
                onerror="{!c.handleError}"
                />

        <lightning:recordEditForm
            onerror="{!c.handleError}"
            objectApiName="Contact">

            <!-- the messages component is for error messages -->
            <lightning:messages />

            <lightning:inputField fieldName="FirstName" />
            <lightning:inputField fieldName="LastName" />
            <lightning:inputField fieldName="Email" />

            <div class="slds-m-top_medium">
                <lightning:button variant="brand" type="submit" name="save" label="Save" />
            </div>
        </lightning:recordEditForm>


    </fieldset>
    </aura:component>

And then add this simple handler:

({
    handleError: function(component, event) {
        var errors = event.getParams();
        console.log("response", JSON.stringify(errors));
    }

})

Finally, create a dummy validation rule to make the save fail, add the component somewhere and try and save a contact

All I see is this generic alert: enter image description here

But more crucially, with the lightning:recordForm, the error handler fires, but the event params response in the handler is totally empty.

With the lightning:recordEditForm, you get the same a generic alert that the save failed, but the response in the handler has the actual error messages at least.

So am I doing something wrong with the new recordForm? Why are there no errors in the response? And with the editform, do I need to write my own handler to expose those messages? Or can I add something else to the form to show the details to the user?

  • Running into the same issue. Have you opened a case with SFDC? – E.J. Wilburn Jun 25 '18 at 22:45
  • The Product Manager said he'd take a look at the example, so waiting on his confirmation before raising a bug. But I ended up reverting to recordEditForm so I could keep moving things forward – BritishBoyinDC Jun 26 '18 at 13:34
  • Any updates on this issue? I have the same problem with the errors handling... – Ruslan Kurchenko Jul 3 '18 at 8:38
  • raised a case with code sample - will let you know if I get a resolution/Known Issue – BritishBoyinDC Jul 3 '18 at 12:51
2

This has now been raised as a Known Issue: https://success.salesforce.com/issues_view?id=a1p3A000000FmjRQAS

0

Hopefully it's not too late, I see the Known Issue is still "In Review" though.

Instead of the generic error message, I found useful to use either:

event.getParam('detail');

or

event.getParam('ouput')['errors'][0]['message']; // event.getParam('ouput')['errors'] is an array of json objects with the property 'message', at least with one error, it's the same of event.getParam('detail').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.