You need to sign in to do that
Don't have an account?
Gaurav Jain 7
Lightning Data Service Basics - Handle Record Changes and Errors
Hi,
I an getting below 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.
accEdit.cmp
accEditcontroller.js
I an getting below 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.
accEdit.cmp
<aura:component implements="flexipage:availableForRecordHome, force:hasRecordId"> <!--inherit recordId attribute--> <aura:attribute name="record" type="Object" /> <aura:attribute name="accountRecord" type="Object" /> <aura:attribute name="recordSaveError" type="String" /> <force:recordData aura:id="recordEditor" layoutType="FULL" recordId="{!v.recordId}" targetError="{!v.recordSaveError}" targetRecord="{!v.record}" targetFields ="{!v.accountRecord}" fields="Name" 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="Billing State" value="{!v.accountRecord.BillingState}" /></p> <p class="slds-text-heading--small"> <lightning:formattedText title="Billing City" value="{!v.accountRecord.BillingCity}" /></p> </div> </lightning:card> </div> <br/> <!-- 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:if isTrue="{!not(empty(v.recordSaveError))}"> <br /> Error: <ui:outputText value="{!v.recordSaveError}"/> </aura:if> </aura:component>
accEditcontroller.js
({ handleSaveRecord: function(cmp, event, helper) { cmp.find("recordEditor").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", ""); } }));} })
May I suggest you please refer the below link for reference.
- https://salesforce.stackexchange.com/questions/179687/lightning-data-service-trailhead-challenge-error-manipulate-records-with-force/179844
- https://developer.salesforce.com/forums/?id=9060G000000BcWWQA0
Let us know if it helps.Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
Thanks
Rahul Kumar
try to give a default value attribute to your aura attribute such as :
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com
I tried this but it is not working
No Success, please find the below code as per your instruction:
accEdit.cmp
accEditcontroller.js
ACCEdit Code
Controller
Any any one please assist. What is wrong.
Replace with