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
Emilien Guichard 40Emilien Guichard 40 

Trailhead module Lightning Data Service Basics - Manipulate Records with force:recordData edit the details of an account

Hi,
I am trying to complete the challenge Lightning Data Service Basics - Manipulate Records with force:recordData and I am getting the followling error on the 'accEdit' component when I try it:
 
Problem saving record, error: [{"fieldErrors":{},"pageErrors":[]}]

Here is my code
accEdit.cmp
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId"> <!--inherit recordId attribute-->

<aura:attribute name="accountRecord" type="Object" />
<aura:attribute name="simpleRecord" type="Object" />
<aura:attribute name="recordError" type="String" />

<force:recordData aura:id="AccountRecordCreator"
	fields="Name"
    recordId="{!v.recordId}"
    targetError="{!v.recordError}"
    targetRecord="{!v.accountRecord}"
    targetFields="{!v.simpleRecord}"
    mode="EDIT" />
    
    <!-- Display an editing form -->
    <ui:outputText value="Edit Account"/>
    <lightning:input aura:id="recordName" name="recordName" label="Account Name"
                  value="{!v.accountRecord.Name}" required="true"/>
    <ui:button label="Save Account" press="{!c.handleSaveRecord}" class="slds-m-top--medium"/>
</aura:component>

accEditController.js
({
    handleSaveRecord: function(component, event, helper) {
        component.find("AccountRecordCreator").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));
            } else {
                console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
            }
        }))
        ;}
})

Could you please help me ?
I am stuck with that for hours...

Thanks a lot.


 
Best Answer chosen by Emilien Guichard 40
Emilien Guichard 40Emilien Guichard 40
This is the code I used that works and passed the challenge

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

    <aura:attribute name="accountRecord" type="Object"/>
    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="newAccountError" type="String"/>

    <force:recordData aura:id="AccountRecordCreator"
    recordId="{!v.recordId}"
    layoutType="FULL"
    targetRecord="{!v.record}"
    targetFields="{!v.accountRecord}"
    targetError="{!v.newAccountError}"
    mode="EDIT"
    fields="Name"/>
    
    <ui:outputText value="Edit Account" class="slds-output" />
    <lightning:input value="{!v.accountRecord.Name}" aura:id="recordName" name="accountRecord" label="Name" />
    <ui:button label="Save Account" press="{!c.handleSaveRecord}" class="slds-m-top--medium"/>

 </aura:component>

accEditController.js
({
    handleSaveRecord : function(component, event, helper) {
        component.find("AccountRecordCreator").saveRecord($A.getCallback(function(saveResult) {
             if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                // handle component related logic in event handler
            } 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));
            } else {
                console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
            }
        }));
    }
})

 

All Answers

Raj VakatiRaj Vakati
Here is the code 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
    
    <aura:attribute name="recordId" type="String" />
    <aura:attribute name="record" type="Object" />
    <aura:attribute name="accountRecord" type="Object" />
    <aura:attribute name="recordSaveError" type="String" default=""/>
    
    
    
    <force:recordData recordId="{!v.recordId}" aura:id="recordEditer"
                      targetRecord="{!v.accountRecord}"
                      targetFields="{!v.accountRecord}"
                      fields="Name"
                      Mode="Edit"/>
    
    
    
    <ui:outputText value="Edit Account"  />
    <lightning:input aura:id="recordName" name="accountRecord" label="Name"
                     value="{!v.accountRecord.Name}" />
    
    <ui:button label="Save Account" press="{!c.handleSaveRecord}" />
    <aura:if isTrue="{!not(empty(v.recordSaveError))}">
        <br />
        Error: <ui:outputText value="{!v.recordSaveError}"/>
    </aura:if>
</aura:component>


({
    handleSaveRecord : function(component, event, helper) {
        var recordLoader = component.find("recordEditer");
        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", "");
            }
        }));
    }
})

 
Emilien Guichard 40Emilien Guichard 40
This is the code I used that works and passed the challenge

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

    <aura:attribute name="accountRecord" type="Object"/>
    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="newAccountError" type="String"/>

    <force:recordData aura:id="AccountRecordCreator"
    recordId="{!v.recordId}"
    layoutType="FULL"
    targetRecord="{!v.record}"
    targetFields="{!v.accountRecord}"
    targetError="{!v.newAccountError}"
    mode="EDIT"
    fields="Name"/>
    
    <ui:outputText value="Edit Account" class="slds-output" />
    <lightning:input value="{!v.accountRecord.Name}" aura:id="recordName" name="accountRecord" label="Name" />
    <ui:button label="Save Account" press="{!c.handleSaveRecord}" class="slds-m-top--medium"/>

 </aura:component>

accEditController.js
({
    handleSaveRecord : function(component, event, helper) {
        component.find("AccountRecordCreator").saveRecord($A.getCallback(function(saveResult) {
             if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                // handle component related logic in event handler
            } 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));
            } else {
                console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
            }
        }));
    }
})

 
This was selected as the best answer
Sumanth_NSKSumanth_NSK
Hi Emilien

Hi All

I am getting this error -
Challenge Not yet complete... here's what's wrong: 
The 'accEdit' Lightning Component does not appear to be using 'lightning:input' with the label 'Account Name' and the value '{!v.accountRecord.Name}'.

Not sure what is wrong here in lightning:input tag, Please help me fix the issue.

here is my code
accEdit Component code
 
<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" />

	<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 -->
	<ui:outputText value="Edit Account" title="Edit Account"/>

	<lightning:input aura:id="recordName" name="recordName" label="Account Name"
                 value="{!v.accountRecord.Name}" required="true"/>

</aura:component>

 
Akihiro AizawaAkihiro Aizawa
Hi Sumanth_NSK,  
I fell into the same pit.  Would you try to make the lightning:input tag to one line and put "label" and "value" to the first in the tag? (i.e. before "aura:id") 

Checking logic of this module seems ... :-<