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
EmilienGuichardEmilienGuichard 

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



 
Best Answer chosen by EmilienGuichard
Sandeep BhanotSandeep Bhanot
The case record has to be accessed as {!v.record.Subject} in order for the data binding to work properly.

All Answers

EmilienGuichardEmilienGuichard
Has anyone completed this challenge already ?
Sandeep BhanotSandeep Bhanot
Hi,
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
EmilienGuichardEmilienGuichard
Hi, thanks for your answer.
I changed the component to the following :
<aura:component controller="DisplayCaseController">
	<aura:attribute name="record" type="Case"/>
	{!c.Subject} {!c.Description} {!c.Status }
</aura:component>
but sadly still got the same error...
Sandeep BhanotSandeep Bhanot
The case record has to be accessed as {!v.record.Subject} in order for the data binding to work properly.
This was selected as the best answer
EmilienGuichardEmilienGuichard
Awesome! Got all the badges now :)
Can't wait for new challenges.

Thanks a lot.
Jurgis Salna 7Jurgis Salna 7
I've passed with the code that actually did not work...

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'/>
Sandeep BhanotSandeep Bhanot
Hi Jurgis - you are indeed correct about the JavaScript controllers challenge! I apologize for that typo - the requirements should have stated ui:inputComponent. We've made the update to the challenge description and you should see it in Trailhead shortly. 
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
Ghanshyam Yadav01Ghanshyam Yadav01
Hi Guys, below component working fine 

<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>
anthony thomas 9anthony thomas 9
I have tried three different orgs and still keep getting the same message : "The component is not using the 'DisplayCaseController' Apex controller" and i have tried several codes also and cannot complete this challenge...#frustrated now
Rudolf HabenbacherRudolf Habenbacher
Do you have the following line in your controller:
<aura:component controller="DisplayCaseController">
Alexander BerehovskiyAlexander Berehovskiy
Probably, you are not allowed to use "c" as variable. Because "c" refers to the reserved word which represents "controller", as "v" represents "view".
Stephen Johnson 13Stephen Johnson 13
Here's the code that worked for me... (I'd forgotten about the array piece as well)

DisplayCaseController.apxc
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];
        }        
    }   

}
DisplayCase.cmp
<aura:component controller="DisplayCaseController" >
    <aura:attribute name="record" type="Case"/>
    <p>{!v.record.Subject}</p>
    <p>{!v.record.Description}</p>
    <p>{!v.record.Status}</p>
</aura:component>
DisplayCaseController.js
({
    getCaseFromId: function(cmp){
        var action = cmp.get("c.getCaseFromId");
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                cmp.set("v.record", response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    }
})

Hope this helps you out!