+ Start a Discussion
Dr. WhoDr. Who 

TrailHead Lightning 'Apex in components' challenge

This client-side DisplayCaseController does not pass the challenge with error "The client side controller does not refer to the 'getCaseFromId' method of the Apex controller class".  Component and controller are pasted below.  The component runs from a test lighnting app.  getCaseFromId is correctly referenced as "var action = component.get("c.getCaseFromId");" in the first line of code


component
<aura:component controller="DisplayCaseController" >
    <aura:attribute name="record" type="Case"/>
	<ui:inputText aura:id="caseId" label="Enter Case Id: "/>
    <ui:button label="Get Case" press="{!c.getCaseRecord}"/><br/>

    Subject: <ui:outputText value="{!v.record.Subject}"/><br/>
    Description: <ui:outputText value="{!v.record.Description}"/><br/>
    Status: <ui:outputText value="{!v.record.Status}" /><br/>
</aura:component>
client-side controller
({
	getCaseRecord : function(component) {
        var action = component.get("c.getCaseFromId");
        var caseId = component.find("caseId").get("v.value");
        action.setParams({ "caseID" : caseId });
        action.setCallback(this, function(action) {
			if (action.getState() === "SUCCESS") {
 				component.set("v.record", action.getReturnValue());
            }
            else {
                alert("Action state: " + action.getState());
            }
        });
        $A.enqueueAction(action);
	}
})
Test Application
<aura:application>
    <c:DisplayCase/>
</aura:application>


 
Best Answer chosen by Dr. Who
joshbirkjoshbirk
It looks correct from what I can tell from here.  You might try it from a completely new DE org, that seems to clear up some random issues that we see.  However, I'd like to be able to investigate what Trailhead is seeing against that particular org.  Can you follow up with me at joshua.birk@salesforce.com?

All Answers

Phil WeinmeisterPhil Weinmeister
Hi Dr. Who,

Only difference I see between what I have (which passed) and yours are the brackets shown below:

Yours:
<aura:attribute name="record" type="Case"/>
Mine:
 
<aura:attribute name="record" type="Case[]"/>

Not sure if those make a difference, but the rest of what you have makes sense. Technically, you don't need any of the following in the client-side controller since the Apex class handles null for ID input:
 
var caseId = component.find("caseId").get("v.value");
        action.setParams({ "caseID" : caseId });
        action.setCallback(this, function(action) {
            if (action.getState() === "SUCCESS") {
                 component.set("v.record", action.getReturnValue());
            }
            else {
                alert("Action state: " + action.getState());
            }
        });

This works in the client-side controller for me:
 
getCase: function(component){
        var action = component.get("c.getCaseFromId");
        action.setCallback(this, function(a){
            component.set("v.record", a.getReturnValue());
        });
     $A.enqueueAction(action);
    }

Thanks,
Phil
joshbirkjoshbirk
It looks correct from what I can tell from here.  You might try it from a completely new DE org, that seems to clear up some random issues that we see.  However, I'd like to be able to investigate what Trailhead is seeing against that particular org.  Can you follow up with me at joshua.birk@salesforce.com?
This was selected as the best answer