You need to sign in to do that
Don't have an account?
Handle Record Changes and Errors Not Setting v.recordSaveError message
I'm trying to complete the Handle Record Changes and Errors module but can't seem to get past the following challenge error:
.I've tried many different combinations of sets and am not having much luck.
I've tried several different component.set methods such as this one:
component.set('v.recordSaveError','Error: ' + saveResult.state + ', message: ' + JSON.stringify(saveResult.error));
Any ideas what this module is looking for as a valid solution?
I do see recordSaveError display after being set due to an error.
Thanks.
Challenge Not yet complete... here's what's wrong: The 'accEdit' Lightning Component JS Controller does not appear to be setting 'v.recordSaveError' with an error message.
.I've tried many different combinations of sets and am not having much luck.
I've tried several different component.set methods such as this one:
component.set('v.recordSaveError','Error: ' + saveResult.state + ', message: ' + JSON.stringify(saveResult.error));
Any ideas what this module is looking for as a valid solution?
I do see recordSaveError display after being set due to an error.
Thanks.
I have just used the given pattern without changing it. Your solution should work but the challenge is waitting for something that is exactly that way:
https://trailhead.salesforce.com/fr/modules/lightning_data_service/units/lightning_data_service_handle_notifications
Regards
I had this pattern at one time but removed it when I got a different message. I thought I had cycled back through all my tried patterns, but apparently did not.
Happy Trails.
John.
You have "some" badges I see: https://trailhead-leaderboard-developer-edition.na35.force.com/
Happy Trails
Alain
Could not find JS controller code for 'accEdit' Lightning Component. Any suggestions would be appreciated. Thanks!!
There is also what appears to be a typo in the instructions:
"If the edits in your editable component create an error, make sure the display component shows an error message."
Considering that we just built an edit component and a display component, this is very misleading -- I first thought the goal was to have an error in the edit component show the error message over in the other display component and built that. But then it became clear they just wanted everything done in the edit component.
This is a really poorly executed challenge -- unclear instructions and dependencies for passing that should not be there.
tag to display your error message. I'm honestly just doing it in both in order to pass this. I took everyone's suggestion from above.
Good Luck on this headache. :)
Putting the error in the format that you suggested worked for me.
I am starting to distrust the final checks on coding projects.. It seems they want something so specific that it almost makes it impossible to get the right answer without looking it up.
This sounds strange because recordSaveError is a string, not a boolean...
It does not really make sense why it would be doing a check like this since it is a string attribute and in the example it has you check if it is not empty. This allowed me to proceed with the Module.
Finally, I'm through and now for the really scary part - the Superbadge.....
I guess for Dustin solution, the aura:if is probably checking if the error message is different than "" (As the default value on the attribute)
accEdit.cmp accEditController
This worked for me! Thanks Dustin
you can find solution here.
http://faizanaz90.blogspot.com/2017/11/lightning-data-service-basics-handle.html
Note mentioned in the post was very helpful. It's worked for me.
Note:
If you keep getting this error "The 'accEdit' Lightning Component JS Controller does not appear to be setting 'v.recordSaveError' with an error message" then make sure in handleSaveRecord function you are using "cmp" not any other name.
He wanted the error message in a div with a "recordError" class !!!!!!!!!! This is nowhere mentioned
Accordnig Rahul Gawale 22
Display error message have to be placed after div edit section. It pass the chalange only in this order :|
Handle Record Changes and Errors
1. accEdit.cmp 2. accDisplay.cmp
3. Controller accEditController.js
Check your challenge... Please mark it as best answer and like.....
Thanks. It works for me fine..
I edited the accEdit component from the previous challenge 'Manipulate Records with force:recordData'
Challenge; "Use force:recordData to create two Lightning components that display and edit the details of an account"
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));
}
}));
}
})
I did log out of SF for 45 minutes before I tested your Code however. Maybe that helped too )
Best,
th
accDisplay.cmp
<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 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="recordError">
{!v.recordSaveError}</div>
</aura:if>
</aura:component>
accEditController
({
handleSaveRecord: function(cmp, event, helper) {
cmp.find("recordEditor").saveRecord($A.getCallback(function(saveResult) {
if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
console.log("Save completed successfully.");
cmp.set("v.recordSaveError", '');
} else if (saveResult.state === "INCOMPLETE") {
console.log("User is offline, device doesn't support drafts.");
cmp.set("v.recordSaveError", '');
} else if (saveResult.state === "ERROR") {
var errMsg = "";
for(var i = 0; i < saveResult.error.length; i++) {
errMsg += saveResult.error[i].message + "\n";
}
cmp.set("v.recordSaveError", errMsg);
} else {
console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
cmp.set("v.recordSaveError", "");
}
}));
},
})
Please try below code, hope this will work .
accEdit.cmp:
-------------------
<aura:component implements="force:hasRecordId,flexipage:availableForRecordHome">
<aura:attribute name="accountRecord" type="Object"/>
<aura:attribute name="recordSaveError" type="String" default=""/>
<!-- Load record in EDIT mode -->
<force:recordData aura:id="recordLoader"
recordId="{!v.recordId}"
fields="Name,Description,Phone"
targetFields="{!v.accountRecord}"
targetError="{!v.recordSaveError}"
mode="EDIT"
recordUpdated="{!c.handleRecordUpdated}" />
<!-- Account edit form -->
<lightning:card iconName="action:edit" title="Edit Accountg">
<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.saveAccount}" />
</div>
</lightning:card>
<!-- Display error message -->
<aura:if isTrue="{!not(empty(v.recordSaveError))}">
<div class="recordSaveError">
{!v.recordSaveError}</div>
</aura:if>
</aura:component>
---------------------------------------------------------------------------------------------------------------------------------------------
accEditController.js:
-----------------------------
({
saveAccount : 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"));
}
}
})
__________________________________________ GoodLuck ______________________________________________________