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
Daniel BallingerDaniel Ballinger 

Trialhead - Using Apex in Components - "The client side controller is not using the return value from the 'getCaseFromId' method"

I'm working through the Using Apex in Components (https://developer.salesforce.com/trailhead/force_com_programmatic_beginner/lightning_components/lightning_components_apex) challenge.

When checking the challenge I'm getting the response:
Challenge not yet complete... here's what's wrong: 
The client side controller is not using the return value from the 'getCaseFromId' method

If I put the same lightning component in an app I can see it is retrieving the Case details via the Apex controller method via the client controller.
Testing working Apex Component
I can see the call going through to the Apex Controller in the logs.
User-added image

I can put a debugger; statement in the client controller within the actions setCallback method and hit that immediately after passing the return value back to the records view attribute.

So I'm fairly certain that the client side controller is using the return value from `getCaseFromId` in the Apex controller.

Any ideas on what the challenge is checking for here?
Best Answer chosen by Daniel Ballinger
joshbirkjoshbirk
Fix is in, I just tested with your version of the controller.  You should be good to go.

All Answers

Mohith Kumar ShrivastavaMohith Kumar Shrivastava
Same problem even I am facing here .

I am getting same error and here is my code 

My component code 
<aura:component controller="DisplayCaseController">
	<aura:attribute name="record" type="Case"/>
    <ui:button label="Get Case" press="{!c.getcase}"/>
    	<p>{!v.record.Status}</p>
        <p>{!v.record.Subject}</p>
        <p>{!v.record.Description}</p>
</aura:component>
My Client side controller code
 
({
	getcase : function(component, record, callback) {
		 var action = component.get("c.getCaseFromId");
          action.setParams({
          "caseID": record.id
      })
          action.setCallback(this,function(action){
             if (action.getState() === "SUCCESS") {
                component.set("v.record", action.getReturnValue());
            }
      });
      $A.enqueueAction(action);
	}
    
})

The apex controller code 
 
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];
        }        
    }
    
    
}

I also have working demo in atleast 3 orgs and all works good but Trailhead throws error


User-added image

Any help will be appreciated .Thanks so much for TrailHead Tutorials .
joshbirkjoshbirk
Yeah, this is an error in the challenge. I've got a fix in the hopper and we'll push it out as soon as responsibly possible.
joshbirkjoshbirk
Fix is in, I just tested with your version of the controller.  You should be good to go.
This was selected as the best answer
Willi WerkelWilli Werkel
Bug is still in.
Rodrigo CruzRodrigo Cruz
I was able to complete this challenge with the following component code:
<aura:component controller="DisplayCaseController">
    <aura:attribute name="record" type="Case"/>
    <ui:button label="Get Case" press="{!c.getCase}"/>
    	<p>{!v.record.Subject}</p>
        <br/>
    	<p>{!v.record.Description}</p>
        <br/>
    	<p>{!v.record.Status }</p>
</aura:component>

And the controller code:
({
    getCase: 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);
    }
})

There seems to be no diference at all from the other's code, but it worked on my org.
 
Tony Thomas 13Tony Thomas 13
I have tried these codes along with others and get the same error "The component is not using the 'DisplayCaseController' Apex controller" not sure why and have tried other new orgs also and i still get that error. HELP! 
David SteeleDavid Steele
mohith_shrivastava's example should work, but alter record.id to record.ID
({
	getcase : function(component, record, callback) {
		 var action = component.get("c.getCaseFromId");
          action.setParams({
          "caseID": record.ID
      })
          action.setCallback(this,function(action){
             if (action.getState() === "SUCCESS") {
                component.set("v.record", action.getReturnValue());
            }
      });
      $A.enqueueAction(action);
	}
    
})