1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting error while completing trailhead challenge

Discussion in 'Programming/Internet' started by Shantanu Mahajan, Oct 8, 2018.

  1. I am getting an error while checking the challenge

    ** Challenge: Use force:recordData to create a component that shows an error message if it is loaded with invalid data**


    Error: The 'accEdit' Lightning Component does not appear to be displaying the 'recordSaveError' value inside a div with the class 'recordError'.

    Please find the code below

    accEdit.cmp

    <aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">

    <aura:attribute name="recordId" type="String" />
    <aura:attribute name="recordError" type="String" />
    <aura:attribute name="record" type="Object" />
    <aura:attribute name="accountRecord" type="Object" />
    <aura:attribute name="recordSaveError" type="String" default=""/>

    <force:recordData aura:id="recordEditor"
    layoutType="FULL"
    recordId="{!v.recordId}"
    targetError="{!v.recordError}"
    targetRecord="{!v.record}"
    targetFields="{!v.accountRecord}"
    fields="Name"
    mode="EDIT" />

    <!-- Display an editing form -->
    <lightning:input label="Account Name" value="{!v.accountRecord.Name}"/>
    <lightning:button label="Save Account" value="{!c.handleSaveRecord}" />

    <aura:if isTrue="{!not(empty(v.recordSaveError))}">
    <div class="recordSaveError">
    Error: <ui:eek:utputText value="{!v.recordSaveError}"/>
    </div>
    </aura:if>

    </aura:component>


    accEditController.js

    ({
    handleSaveRecord: function(cmp, event, helper) {
    cmp.find("recordEditor").saveRecord($A.getCallback(function(saveResult) {
    if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
    console.log("Save completed successfully.");
    cmp.set("v.recordSaveError", '');
    } else if (saveResult.state === "INCOMPLETE") {
    console.log("User is offline, device doesn't support drafts.");
    cmp.set("v.recordSaveError", '');
    } else if (saveResult.state === "ERROR") {
    var errMsg = "";
    // console.log('Problem saving record, error: ' + JSON.stringify(saveResult.error));
    // saveResult.error is an array of errors,
    // so collect all errors into one message
    for(var i = 0; i < saveResult.error.length; i++) {
    errMsg += saveResult.error.message + "\n";
    }
    cmp.set("v.recordSaveError", errMsg);

    } else {
    console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
    cmp.set("v.recordSaveError", "");
    }
    }));
    },
    })

    Login To add answer/comment
     

Share This Page