You need to sign in to do that
Don't have an account?
EmilienGuichard
Stuck on Using Apex in Components Lightning challenge
Hello all,
I'm stuck with the Lightning challenge "Using Apex in Components" :
here is the component :
"Challenge not yet complete... here's what's wrong:
The component is not binding to the Case Subject value "
Could you please advise ?
Thanks a lot!
I'm stuck with the Lightning challenge "Using Apex in Components" :
here is the component :
<aura:component controller="DisplayCaseController"> <aura:attribute name="record" type="Case[]"/> <aura:iteration items="{!v.record}" var="c"> {!c.Subject}, {!c.Description}, {!c.Subject}, {!c.Status } </aura:iteration> </aura:component>the component controller :
({ getRecord: function(cmp){ var action = cmp.get("c.getCaseFromId"); action.setCallback(this, function(response){ var state = response.getState(); console.log(state); if (state === "SUCCESS") { cmp.set("v.record", response.getReturnValue()); } }); $A.enqueueAction(action); } })and the apex controller (provided for the challenge)
public class DisplayCaseController { @AuraEnabled public static Case getCaseFromId(Id caseID) { if(caseID == null) { return [SELECT ID, Subject, Description, STATUS from Case LIMIT 1]; } List<Case> cases = [ SELECT Id, Subject, Description, Status from CASE where ID = :caseID ]; if(cases.size() == 0) { return [SELECT ID, Subject, Description, STATUS from Case LIMIT 1]; } else { return cases[0]; } } }and still when hitting the Check challenge button, the following error is displayed :
"Challenge not yet complete... here's what's wrong:
The component is not binding to the Case Subject value "
Could you please advise ?
Thanks a lot!
All Answers
In your component, you've defined your attribute as an array of Case records. The challenge (and the JS and Apex controllers) work on a single Case record. If you remove your array (and the iteration component), you should be able to pass the challenge. Hope this helps!
Sandeep Bhanot
Salesforce.com
I changed the component to the following : but sadly still got the same error...
Can't wait for new challenges.
Thanks a lot.
I think what challengers meant that you'll actually need two attributes - one CaseId of type ID (supplied via URL) and one record of type Case.
The write up of these challenges are quite poor. Just like in challenge "Using JavaScript Controllers with Components" they state have three aura:inputNumber components.
The component aura:inputNumber does not exist! What worked instead was <ui:inputNumber aura:id='inputOne'/>
I would love to get feedback/ideas on how we can improve the wording for the Apex challenge as well. I'd really appretiate if you could drop me an email at sbhanot@salesforce.com with your ideas. Thanks for trying Trailhead and helping us improve it.
Sandeep Bhanot
Salesforce.com
<aura:component controller="DisplayCaseController">
<aura:attribute name="record" type="Case[]"/>
<aura:iteration items="{!v.record.Subject}" var="c">
{!c.Subject}, {!c.Description}, {!c.Subject}, {!c.Status }
</aura:iteration>
<aura:iteration items="{!v.record.Description}" var="c">
{!c.Subject}, {!c.Description}, {!c.Subject}, {!c.Status }
</aura:iteration>
<aura:iteration items="{!v.record.Status}" var="c">
{!c.Subject}, {!c.Description}, {!c.Subject}, {!c.Status }
</aura:iteration>
</aura:component>
<aura:component controller="DisplayCaseController">
DisplayCaseController.apxc DisplayCase.cmp DisplayCaseController.js
Hope this helps you out!