You need to sign in to do that
Don't have an account?
Akhilesh 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!
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>
<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", "");
}
}));
}
})
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
Here is the working code and able to clear the challenge:
I did this to clear the challenge
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));
}
}));
}
})
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.
Your methods for the lightning card (accDisplay cmp) and displaying the edit form (accEdit cmp) worked for me. Thank you!
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.
<lightning:input label="Account Name"
name="AccountName"value="{!v.accountRecord.Name}" /> <br/>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
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 ....
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.
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
accEdit.cmp
accEditController.jsGo 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.
Mode should be in the Small caps , it took my 3 productive hours to trouble shoot.
Here is the working code,
accDisplay.cmp accDisplayController.js
accEdit.cmp
Please mark this as a solution and provide kudos if you like this to be helpful.
Thanks!
accDisplay.cmp
accEdit.cmp
Thanks
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)