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
Akhilesh Reddy BaddigamAkhilesh Reddy Baddigam 

Lightning Data Service Trailhead Challenge Error (Manipulate Records with force:recordData)

Hi Can some one explain me how to use two components with Lightning Data Service, i tried the following code for accDisplay and accEdit.
This worked as i expected but i got the following error!

I am missing some thing, can some one explain me how LDS works with multiple componets!
 
Challenge Not yet complete... here's what's wrong: 
The 'accDisplay' Lightning Component does not appear to be displaying the 'Name' using 'ui:outputText' and the value 'v.accountRecord.Name
 
<!--accDisplay component-->
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
 <aura:attribute name="accountRecord" type="Object" />
<force:recordData aura:id="AccountRecordCreator"
    recordId="{!v.recordId}"
    layoutType="FULL"
    targetRecord="{!v.accountRecord}"
    targetFields="{!v.simpleNewAccount}"
    targetError="{!v.newContactError}"
                  mode="VIEW"
    />
   



    <!-- Display a header with details about the record -->
    <div class="slds-form--stacked">
        <div class="slds-form-element">
            <label class="slds-form-element__label" for="recordName">Name: </label>
            <div class="slds-form-element__control">
              <ui:outputText class="slds-input" aura:id="recordName"
                value="{!v.simpleNewAccount.Name}" />
            </div>
            <label class="slds-form-element__label" for="recordIndustry">Industry: </label>
            <div class="slds-form-element__control">
              <ui:outputText class="slds-input" aura:id="recordIndustry"
                value="{!v.simpleNewAccount.Industry}" />
            </div>
             <label class="slds-form-element__label" for="recordDescription">Description: </label>
            <div class="slds-form-element__control">
              <ui:outputTextArea class="slds-input" aura:id="recordDescription"
                value="{!v.simpleNewAccount.Description}" />
            </div>
             <label class="slds-form-element__label" for="recordPhone">Phone: </label>
            <div class="slds-form-element__control">
              <ui:outputPhone class="slds-input" aura:id="recordPhone"
                value="{!v.simpleNewAccount.Phone}" />
            </div>
        </div>
    </div>

   

   
</aura:component>
<!--accEdit-->
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">

<aura:attribute name="accountRecord" type="Object"/>
<aura:attribute name="simpleNewAccount" type="Object"/>
<aura:attribute name="newContactError" type="String"/>

<force:recordData aura:id="AccountRecordCreator"
    recordId="{!v.recordId}"
    layoutType="FULL"
    targetRecord="{!v.accountRecord}"
    targetFields="{!v.simpleNewAccount}"
    targetError="{!v.newContactError}"
                  mode="EDIT"
    />
   
    <ui:outputText class="slds-output" 
                value="Edit Account" />
     <lightning:input aura:id="recordName" name="accountRecord" label="Name"
                  value="{!v.simpleNewAccount.Name}" />

     <lightning:button label="Save Account" onclick="{!c.handleSaveRecord}"
               variant="brand" class="slds-m-top--medium"/>
</aura:component>

 
CMielczarskiCMielczarski
It looks like you may be missing a few attributes, at least with how they intend for you to accomplish it.  Try the following for the display component:
<aura:component implements="flexipage:availableForRecordHome,force:lightningQuickActionWithoutHeader,force:hasRecordId">
	<aura:attribute name="account" type="Object"/>
    <aura:attribute name="accountRecord" type="Object"/>
    <aura:attribute name="recordError" type="String"/>

    <force:recordData aura:id="accountRecordLoader"
      recordId="{!v.recordId}"
      layoutType="FULL"
      targetRecord="{!v.account}"
      targetFields="{!v.accountRecord}"
      fields="Name,Industry,Description,Phone"
      targetError="{!v.recordError}"
      />

    <!-- Display a header with details about the record -->
    <div class="slds-page-header" role="banner">
        <ui:outputText value="{!v.accountRecord.Name}"/>
        <ui:outputText value="{!v.accountRecord.Industry}"/>
        <ui:outputTextArea value="{!v.accountRecord.Description}"/>
        <ui:outputPhone value="{!v.accountRecord.Phone}"/>
    </div>

    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordError))}">
        <div class="recordError">
            <ui:message title="Error" severity="error" closable="true">
                {!v.recordError}
            </ui:message>
        </div>
    </aura:if>
</aura:component>

 
Akhilesh Reddy BaddigamAkhilesh Reddy Baddigam
CMielczarski it worked for me so i am missing account attribute for the target record, as trailhead is expecting accountRecord for target fields. thanks for your help. 
Manj_SFDCManj_SFDC
AccDisplay Component: 
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome">

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

     <force:recordData recordId="{!v.recordId}"
          targetRecord="{!v.record}"
          targetFields="{!v.accountRecord}"
          fields="Id, Name"/>

    <ui:outputText value="{!v.accountRecord.Name}"/>
    <ui:outputText value="{!v.accountRecord.Industry}"/>
    <ui:outputTextArea value="{!v.accountRecord.Description }"/>
    <ui:outputPhone value="{!v.accountRecord.Phone}"/>

</aura:component>


AccEdit Component : 

<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>

controller :

({
    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", "");
            }
        }));
    }
})
Sumanth_NSKSumanth_NSK
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>

 
Yves Asselin 3Yves Asselin 3
Any answers on this questions yet? I get exactly the same problem...
Pratap P 9Pratap P 9
Component: accEdit
Here is the working code and able to clear the challenge:
 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId"> <!--inherit recordId attribute-->

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

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

    <!-- Display an editing form -->
    <div calss="Edit Account">
        <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" onclick="{!c.handleSaveRecord}" variant="brand"/>
            </div>    
        </lightning:card>    
    </div>  
    
    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordSaveError))}">
        <div class="recordSaveError">
            {!v.recordSaveError}</div>
    </aura:if>
</aura:component>

 
Sumanth_NSKSumanth_NSK
Hi Yves Asselin 3

I did this to clear the challenge
Before 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>

After Changes
I have removed these lines --- <aura:id="recordName" name="recordName" >
from lightning:input tag, Although its correct way to have IDs specified, but the trailhead
robot is not accepting the challenge,  Try this, you should be able to clear the challenge.

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

-------------------------------------------------------------------------------------------------------------------------

<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   label="Account Name"  value="{!v.accountRecord.Name}" />

</aura:component>


 
Ghanshyam Yadav19Ghanshyam Yadav19
Hi Everyone,
Below code working fine for me. Please mark best answer, so anyone else can benefit.

accDisplay.cmp

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId"> <!--inherit recordId attribute-->

<aura:attribute name="record" type="Account" 
  description="The record object to be displayed"/>
<aura:attribute name="accountRecord" type="Account" 
  description="A simplified view record object to be displayed"/>
<aura:attribute name="recordError" type="String" 
  description="An error message bound to force:recordData"/>

<force:recordData aura:id="record"
    layoutType="FULL"
    recordId="{!v.recordId}"
    targetError="{!v.recordError}"
    targetRecord="{!v.record}"
    targetFields="{!v.accountRecord}"
    mode="VIEW"/>
    
    <!-- Display a lightning card with details about the record -->
<div class="Record Details"> 
    <lightning:card iconName="standard:account" title="{!v.accountRecord.Name}" >
        <div class="slds-p-horizontal--small">
            <p class="slds-text-heading--small">
                <lightning:formattedText title="Industry" value="{!v.accountRecord.Industry}" /></p>
            <p class="slds-text-heading--small">
                <lightning:formattedText title="Description" value="{!v.accountRecord.Description}" /></p>
            <p class="slds-text-heading--small">
                <lightning:formattedPhone title="Phone" value="{!v.accountRecord.Phone}" /></p>
        </div>
    </lightning:card>
</div>

<!-- Display Lightning Data Service errors, if any -->
<aura:if isTrue="{!not(empty(v.recordError))}">
    <div class="recordError">
        {!v.recordError}</div>
</aura:if>

</aura:component>

--------------------------------------------------------------------------------------------------------------------

accEdit.cmp

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId"> <!--inherit recordId attribute-->

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

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

    <!-- Display an editing form -->
    <div calss="Edit Account">
        <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" onclick="{!c.handleSaveRecord}" variant="brand"/>
            </div>    
        </lightning:card>    
    </div>  
    
    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordSaveError))}">
        <div class="recordSaveError">
            {!v.recordSaveError}</div>
    </aura:if>
</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));
            }
        }));
    }
})


 
ramesh k 29ramesh k 29

Hi everyone,

i am getting follwoing error

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

M ParnellM Parnell
@Ghanshyam Yadav19
Your methods for the lightning card (accDisplay cmp) and displaying the edit form (accEdit cmp) worked for me. Thank you!
ashutosh belwalashutosh belwal
Hi All 

Does anyone have a solution for this? I am still getting error message from AccEdit.cmp 

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}'.


And my code is.
 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId"> 
    <aura:attribute name="accountRecord" type="Object" />
    <aura:attribute name="recordSaveError" type="String" />
    
    <force:recordData aura:id="recordEditor"
                      recordId="{!v.recordId}"
                      targetError="{!v.recordSaveError}"
                      targetFields="{!v.accountRecord}"
                      mode="EDIT" 
                      fields="Name" />
    
    <!-- Display an editing form -->
    <div calss="Edit Account">
        <lightning:card iconName="action:edit" title="Edit Account">
            <div class="slds-p-horizontal--small">
                <lightning:input label="Account Name" name="AccountName" value="{!v.accountRecord.Name}" /> <br/>
                <lightning:button label="Save Account" onclick="{!c.handleSaveRecord}" variant="brand"/>
            </div>    
        </lightning:card>    
    </div>  
    
    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordSaveError))}">
        <div class="recordSaveError">
            {!v.recordSaveError}</div>
    </aura:if>
</aura:component>
 
({
    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));
            }
        }));
    }
})

 
mahesh chilakamahesh chilaka
Remove name attribute from input tag : 
 <lightning:input label="Account Name" name="AccountName" value="{!v.accountRecord.Name}" /> <br/>

 
Andrew WeinsteinAndrew Weinstein
The instructions for this page/challenge are pretty poor. They don't make clear the distinction between targetRecord and targetFields, or that you can't assign those two attributes to the same variable. It seems like targetRecord should be accountRecord, but in order to complete the challenge, you have to make targetRecord something else and assign targetFields to accountRecord.
Dipika RajputDipika Rajput

I have completed this challenge successfully by using following code please mark this answer as correct answer if this works for you so other can also refer this:
accDisplay.cmp

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="account" type="Object"/>
    <aura:attribute name="accountRecord" type="Object"/>
    <aura:attribute name="recordError" type="Object"/>
    <force:recordData aura:id="AccountRecordCreator"
                      recordId= "{!v.recordId}"
                      layoutType="FULL"
                      targetRecord="{!v.account}"
                      targetFields="{!v.accountRecord}"
                      fields="Name,Industry,Description,Phone"
                      targetError = "recordError"/>
    <!-- Display a lightning card with details about the record -->
    <div class="Record Details"> 
        <lightning:card iconName="standard:account" title="{!v.accountRecord.Name}">
            <div class="slds-p-horizontal--small">
                <p class="slds-text-heading--small">
                    <lightning:formattedText title="Industry" value="{!v.accountRecord.Industry}" /></p>
                <p class="slds-text-heading--small">
                    <lightning:formattedText title="Description" value="{!v.accountRecord.Description }" /></p>
                <p class="slds-text-heading--small">
                    <lightning:formattedPhone title="Phone" value="{!v.accountRecord.Phone }" /></p>
            </div>
        </lightning:card>
    </div>
</aura:component>

====================================================

accEdit.cmp

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="accountRecord" type="Object"/>
    <aura:attribute name="recordError" type="Object"/>
    
    <force:recordData recordId="{!v.recordId}"
                      aura:id="RecordEdit"
                      targetRecord = "{!v.accountRecord}"
                      targetError="{!v.recordError}"
                       fields="Name"
                      Mode="Edit"/>
    
    <ui:outputText value="Edit the Account"></ui:outputText>
    <lightning:input aura:Id="recordName"
                     label="Account Name"
                     value="{!v.accountRecord.Name}"/>
    
    <lightning:button label="Save Account" onclick="{!c.handleSaveRecord}"/>
</aura:component>

=====================================

accEditController.js

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

========================

-after this go to account record detail page in lightning experience env .

-click on setting--->Edit Page -->it will redirect you on lightning app builder.
-then add accDisplay.cmp and accEdit.cmp component from custom section 
-save this changes
-activate the page
-assign it to org Default and save the changes
-Go back to account detail page.
-And its ready to use
 

 

Thomas HThomas H
Hello Dipika     Good evening to You )    ---- This worked !   Thanks -- clever approach  )

See API version error in Lightning App Builder (Page) attached  --- still worked ....

Also -- Reading your NOTES on the bottom of you post were the Key to solbeve this Puzzle )
It might not be obvious how to find and add the widgets onto the Lightning Page with App Builder ....


                                   accDisplay.cmp API version error to Add to Lightning Page 
   
If you look at the top of the error message and to the left of the message -- you will see accDisplay & accEdit both on the Page and as Selections to Add to the Page.   
Rajat Sharma 84Rajat Sharma 84

Here is my code which clear the challenge, but i am struggling to edit the account name in the actual application (which i would trouble shoot and fix it)

To understand LDS in more details, you may watch the following salesforceDx Video as well  https://www.youtube.com/watch?v=nHYnt0t0_NI

accDisplay.cmp

<!--
 - Created by Rajat on 1/24/2019.
 -->

<aura:component implements="flexipage:availableForRecordHome, force:hasRecordId"> <!--inherit recordId attribute-->
    <aura:attribute name="account" 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="recordError" type="String"
                    description="An error message bound to force:recordData"/>
    <force:recordData aura:id="AccountRecordCreator"
                      layoutType="FULL"
                      recordId="{!v.recordId}"
                      targetError="{!v.recordError}"
                      targetRecord="{!v.account}"
                      targetFields ="{!v.accountRecord}"
                      fields="Name,Industry,Description,Phone"
                      mode="VIEW"/>

    <!-- Display a lightning card with details about the record -->
    <div class="Record Details">
        <lightning:card iconName="standard:account" title="{!v.accountRecord.Name}" >
            <div class="slds-p-horizontal--small">
                <p class="slds-text-heading--small">
                    <lightning:formattedText title="Industry" value="{!v.accountRecord.Industry}" /></p>
                <p class="slds-text-heading--small">
                    <lightning:formattedText title="Description" value="{!v.accountRecord.Description }" /></p>
                <p class="slds-text-heading--small">
                    <lightning:formattedPhone title="Phone" value="{!v.accountRecord.Phone}" /></p>
            </div>
        </lightning:card>
    </div>
    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordError))}">
        <div class="recordError">
            {!v.recordError}</div>
    </aura:if>
</aura:component>
 

accEdit.cmp

<!--
 - Created by Rajat on 1/24/2019.
 -->

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

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

    <force:recordData recordId="{!v.recordId}"
                      aura:id="RecordEdit"
                      targetRecord="{!v.simpleRecord}"
                      targetError="{!v.recordError}"
                      targetFields="{!v.accountRecord}"
                      fields="Name,Industry,Description,Phone"
                      Mode="Edit"/>

    <!-- Display a lightning card with details about the record -->
    <div class="Record Details">
        <lightning:card iconName="standard:account" title="{!v.accountRecord.Name}">
            <div class="slds-p-horizontal--small">
                <p class="slds-text-heading--small">
                    <lightning:formattedText title="Industry" value="{!v.accountRecord.Industry}"/>
                </p>
                <p class="slds-text-heading--small">
                    <lightning:formattedText title="Description"
                                             value="{!v.accountRecord.Description }"/>
                </p>
            </div>
        </lightning:card>
    </div>

    <br/>

    <div class="Record Details">
        <lightning:card iconName="action:edit" title="Edit Account">
            <div class="slds-p-horizontal--small">
                <lightning:input label="Account Name" aura:Id="AccountName"
                                 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.recordError))}">
        <div class="recordError">
            {!v.recordError}</div>
    </aura:if>
</aura:component>
accEditController.js
/**
 * Created by Rajat on 1/24/2019.
 */
({
    handleSaveRecord: function (component, event, helper) {
        //console.log('inside the HandleSave Record method');
        var recordEditor = component.find("RecordEdit");
        recordEditor.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));
            }
        }));

    }
})
 



Go to the Account Record
Click Edit the Page
Add both the new Lightning components you have created above.

This is my first solution, if you like it and it works for you, kindly click on the like button please.

 

Rajat Sharma 84Rajat Sharma 84
Hey an issue why i am not able to edit the Account Name, silly mistake :(

Mode should be in the Small caps , it took my 3 productive hours to trouble shoot.
<force:recordData aura:id="RecordEdit"
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      targetRecord="{!v.accountRecord}"
                      targetError="{!v.recordError}"
                      targetFields="{!v.simpleNewAccount}"
                      fields="Name,Industry,Description,Phone"
                      mode="EDIT"/>


 
Francis CrumpFrancis Crump
Thanks Rajat, it worked and the others seemed to not for me.
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan
Hi, 

Here is the working code, 

accDisplay.cmp
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
 <aura:attribute name="record" type="Object" 
      description="The record object to be displayed"/>
    <aura:attribute name="simpleRecord" type="Object" 
      description="A simplified view record object to be displayed"/>
    <aura:attribute name="recordError" type="String" 
      description="An error message bound to force:recordData"/>
    
    <force:recordData aura:id="accountRecord"
        layoutType="FULL"
        recordId="{!v.recordId}"
        targetError="{!v.recordError}"
        targetRecord="{!v.record}"
        targetFields ="{!v.simpleRecord}"
        mode="VIEW"/>
    <!-- Display a lightning card with details about the record -->
    <div class="Record Details"> 
        <lightning:card iconName="standard:account" title="{!v.accountRecord.Name}" >
            <div class="slds-p-horizontal--small">
                <p class="slds-text-heading--small">
                    <lightning:formattedText title="Name" value="{!v.accountRecord.Name}" /></p>
                <p class="slds-text-heading--small">
                    <lightning:formattedText title="Industry" value="{!v.accountRecord.Industry}" /></p>
                <p class="slds-text-heading--small">
                    <lightning:formattedText title="Description" value="{!v.accountRecord.Description}" /></p>
                <p class="slds-text-heading--small">
                    <lightning:formattedPhone title="Phone" value="{!v.accountRecord.Phone}" /></p>
            </div>
        </lightning:card>
    </div>
        
    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordError))}">
        <div class="recordError">
            {!v.recordError}</div>
    </aura:if>
</aura:component>
accDisplayController.js
({
    handleSaveRecord: function(component, event, helper) {
        component.find("accountRecord").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));
            }
        }));}
})

accEdit.cmp
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
 <aura:attribute name="record" type="Object" 
      description="The record object to be displayed"/>
    <aura:attribute name="simpleRecord" type="Object" 
      description="A simplified view record object to be displayed"/>
    <aura:attribute name="recordError" type="String" 
      description="An error message bound to force:recordData"/>
    
    <force:recordData aura:id="accountRecord"
        layoutType="FULL"
        recordId="{!v.recordId}"
        targetError="{!v.recordError}"
        targetRecord="{!v.record}"
        targetFields ="{!v.simpleRecord}"
        fields="Name"
        mode="EDIT"/>
    
     <!-- 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>
</aura:component>

Please mark this as a solution and provide kudos if you like this to be helpful.

Thanks!
lakshmikanth saikumarlakshmikanth saikumar
This is working code.. 
accDisplay.cmp
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="accountRecord" type="Object" />
    <aura:attribute name="simpleAccountRecord" type="Object" />
    <aura:attribute name="accountRecordError" type="string" />
    
    <force:recordData aura:id="accountRecordDisplay"
                      layoutType="FULL"
                      recordId="{!v.recordId}"
                      targetRecord="{!v.simpleAccountRecord}"
                      targetFields="{!v.accountRecord}"
                      targetError="{!v.accountRecordError}"
                      mode="VIEW" />
    
    <lightning:card iconName="standard:account" title="{!v.accountRecord.Name}" >
        <div class="slds-p-horizontal--small">
            <p class="slds-text-heading--small">
                <lightning:formattedText title="Industry" value="{!v.accountRecord.Industry}" /> </p>
            <p class="slds-text-heading--small">
                <lightning:formattedText title="Description" value="{!v.accountRecord.Description}" /> </p>
            <p class="slds-text-heading--small">
                <lightning:formattedPhone title="Phone" value="{!v.accountRecord.Phone}" /> </p>
        </div>
    </lightning:card>
    
    <aura:if isTrue="{!not(empty(v.recordError))}">
        <div class="recordError">
            {!v.recordError}
        </div>
    </aura:if>
</aura:component>

accEdit.cmp
 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="accountRecord" type="Object" />
    <aura:attribute name="simpleAccountRecord" type="Object" />
    <aura:attribute name="accountRecordError" type="string" />
    <aura:attribute name="fields" type="string[]" default="['Name']" />
    
    <force:recordData aura:id="accountRecordDisplay"
                      fields="{!v.fields}"
                      recordId="{!v.recordId}"
                      targetRecord="{!v.simpleAccountRecord}"
                      targetFields="{!v.accountRecord}"
                      targetError="{!v.accountRecordError}"
                      mode="EDIT" />
    
    <div class="Edit Account">
        <lightning:card iconName="action:edit" title="{!v.accountRecord.Name}" >
            <div class="slds-p-horizontal--small">
                <lightning:input name="Account Name" label="Account Name" value="{!v.accountRecord.Name}" />
                <br />
                <lightning:button label="Save Account" variant="brand" onclick="{!c.handleSaveAccount}" />
            </div>
        </lightning:card>
    </div>
    
    <aura:if isTrue="{!not(empty(v.accountRecordError))}" >
        <div class="recordError">
            {!v.accountRecordError}
        </div>
        
    </aura:if>
    
</aura:component>

Thanks
raj_sfdccraj_sfdcc
Hi all,
you can use below post if you face any more erros :
Lightning Data Service module passed (https://salessforcehacks.blogspot.com/2020/02/lightning-data-service-basics-for-aura.html)
Pratik Gangawane 7Pratik Gangawane 7
Just go through setup>>lightning app builder>> and check  for account_record_page with object "Account"  if not created>>create one and then edit by adding both accDisplay and accEdit component. worked for me with same code.