function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pradeepkumar Dani 5Pradeepkumar Dani 5 

Challenge Not yet complete... here's what's wrong: The 'accEdit' Lightning Component does not appear to be checking if 'v.recordSaveError' is true.

Somehow I was not able to complete this challenge due to above error:
 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">

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

    <force:recordData aura:id="recordHandler"
    recordId="{!v.recordId}"
    layoutType="FULL"
    targetRecord="{!v.record}"
    targetFields="{!v.accountRecord}"
    targetError="{!v.recordSaveError}"
    mode="EDIT"
    fields="Name"/>
    
    <!-- Display an editing form -->
    <div class="Record Details">
        <lightning:card iconName="action:edit" title="Edit Account">
            <div class="slds-p-horizontal--small">
                <lightning:input  label="Account Name" value="{!v.accountRecord.Name}"  name="Account Name"  />
                <br/>
                <lightning:button label="Save Account" onclick="{!c.handleSaveRecord}" class="slds-m-top--medium"/>
            </div>
        </lightning:card>
    </div>
        
    <!-- Display error message -->
    <aura:if isTrue="{!not(empty(v.recordSaveError))}">
        Error: <ui:outputText value="{!v.recordSaveError}"/>
    </aura:if>
 
 </aura:component>
 
({
    handleSaveRecord : function(component, event, helper) {
        component.find("recordHandler").saveRecord($A.getCallback(function(saveResult) {
            if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                // handle component related logic in event handler
                component.set("v.recordSaveError", "");
                                
            } else if (saveResult.state === "INCOMPLETE") {
                console.log("User is offline, device doesn't support drafts.");
            } else if (saveResult.state === "ERROR") {
                console.log('Problem saving record, error: ' + JSON.stringify(saveResult.error));
                var errMsg = "";
                // 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[i].message + "\n";
                }
                component.set("v.recordSaveError", errMsg);                
                
            } else {
                console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
            } 
        })); 
    }
})

Please help, Thanks :) 
Best Answer chosen by Pradeepkumar Dani 5
Pradeepkumar Dani 5Pradeepkumar Dani 5

I found the issue ( after a bilion attempts! ). Challenge evalution was looking for code something like below.

<!-- Display error message -->
        <aura:if isTrue="{!v.recordSaveError}">
            <div class="recordError">
                {!v.recordSaveError}
            </div> 
        </aura:if>

All Answers

Pradeepkumar Dani 5Pradeepkumar Dani 5

Even checked with follwing way of achieving same thing:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
    
    <aura:attribute name="accountRecord" type="Account"/>
    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="recordSaveError" type="String" default=""/>
    
    <force:recordData aura:id="recordLoader"
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      targetRecord="{!v.record}"
                      targetFields="{!v.accountRecord}"
                      targetError="{!v.recordSaveError}"
                      recordUpdated="{!c.handleRecordUpdated}"
                      mode="EDIT"
                      fields="Name"/>
    
    <!-- Display an editing form -->
    <div class="Record Details">
        <lightning:card iconName="action:edit" title="Edit Account">
            <div class="slds-p-horizontal--small">
                <lightning:input  label="Account Name" value="{!v.accountRecord.Name}"  name="Account Name"  />
                <br/>
                <lightning:button label="Save Account" onclick="{!c.handleSaveRecord}" class="slds-m-top--medium"/>
            </div>
        </lightning:card>
    </div>
    
    <!-- Display error message -->
    <aura:if isTrue="{!not(empty(v.recordSaveError))}">
        Error: <ui:outputText value="{!v.recordSaveError}"/>
    </aura:if>
    
</aura:component>
 
({
    handleSaveRecord : function(cmp, event, helper) {
        var recordLoader = cmp.find("recordLoader");
        recordLoader.saveRecord($A.getCallback(function(saveResult) {
            if (saveResult.state === "ERROR") {
                var errMsg = "";
                // 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[i].message + "\n";
                }
                cmp.set("v.recordSaveError", errMsg);
            } else {
                cmp.set("v.recordSaveError", "");
            }
        }));
    },

    // Control the component behavior here when record is changed (via any component)
    handleRecordUpdated: function(component, event, helper) {
        var eventParams = event.getParams();
        if(eventParams.changeType === "CHANGED") {
            // get the fields that are changed for this record
            var changedFields = eventParams.changedFields;
            console.log('Fields that are changed: ' + JSON.stringify(changedFields));
            // record is changed so refresh the component (or other component logic)
            var resultsToast = $A.get("e.force:showToast");
            resultsToast.setParams({
                "title": "Saved",
                "message": "The record was updated."
            });
            resultsToast.fire();
        } else if(eventParams.changeType === "LOADED") {
            // record is loaded in the cache
        } else if(eventParams.changeType === "REMOVED") {
            // record is deleted and removed from the cache
        } else if(eventParams.changeType === "ERROR") {
            console.log('Error: ' + component.get("v.error"));
        }
    }
})

Its still not passing :(
Pradeepkumar Dani 5Pradeepkumar Dani 5

I found the issue ( after a bilion attempts! ). Challenge evalution was looking for code something like below.

<!-- Display error message -->
        <aura:if isTrue="{!v.recordSaveError}">
            <div class="recordError">
                {!v.recordSaveError}
            </div> 
        </aura:if>
This was selected as the best answer
Mats BöhlerMats Böhler
This was ridiculous. Following code works...
 
<aura:if isTrue="{!v.recordSaveError}">
        <div class="recordError">
            {!v.recordSaveError}
        </div> 
</aura:if>

 
Priyank AnandPriyank Anand
Try This
 <aura:if isTrue="{!not(empty(v.recordSaveError))}">
        <div class="recordError">
            {!v.recordSaveError}</div>
    </aura:if>
Ankur ShresthaAnkur Shrestha
<aura:if isTrue="{!not(empty(v.recordSaveError))}">
        <div class="recordSaveError">
            <ui:message title="Error" severity="error" closable="true">
                {!v.recordSaveError}
            </ui:message>
            Error: <ui:outputText value="{!v.recordSaveError}"/>
        </div>
    </aura:if>

 
Jhonny Alexander Ramirez ChiroqueJhonny Alexander Ramirez Chiroque
A mi funciono con este codigo

accEdit.cmp
<aura:component implements="force:hasRecordId,flexipage:availableForRecordHome">
    <aura:attribute name="record"
                    type="Object"
                    description="The record object to be displayed"/>
    <aura:attribute name="accountRecord"
                    type="Object"
                    description="A simplified view record object to be displayed"/>
    <aura:attribute name="recordSaveError"
                    type="String"
                    description="An error message bound to force:recordData"/>
    
    <force:recordData aura:id="accountRecordId"
                      recordId="{!v.recordId}"
                      fields="Name"
                      mode="EDIT"
                      targetRecord="{!v.record}"
                      targetFields="{!v.simpleRecord}"
                      targetError="{!v.recordSaveError}"/>
    
    
    <!-- Display an editing form -->
    <div class="Record Details">
        <lightning:card iconName="action:edit" title="Edit Account">
            <div class="slds-p-horizontal--small">
                <lightning:input label="Account Name" value="{!v.accountRecord.Name}"/>
                <br/>
                <lightning:button label="Save Account" variant="brand" onclick="{!c.handleSaveRecord}" />
            </div>
        </lightning:card>
    </div>
    
    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordSaveError))}">
        <div class="recordError">
            {!v.recordSaveError}
        </div>
    </aura:if>
</aura:component>



accEditController.js
--------------------------
({
    handleSaveRecord : function(component, event, helper) {
        component.find("accountRecordId").saveRecord($A.getCallback(function(saveResult) {
            if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                console.log("Save completed successfully.");
            } else if (saveResult.state === "INCOMPLETE") {
                console.log("User is offline, device doesn't support drafts.");
            } else if (saveResult.state === "ERROR") {
                console.log('Problem saving record, error: ' + 
                            JSON.stringify(saveResult.error));
                var errMsg = "";
                for (var i = 0; i < saveResult.error.length; i++) {
                    errMsg += saveResult.error[i].message + "\n";
                }
                component.set("v.recordSaveError", errMsg);
            } else {
                console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
            }
        }));
    }
})