+ Start a Discussion
Ben MyhreBen Myhre 

How to resolve Trailhead Challenge issues for Developer Beginner > Visualforce Basics > Creating & Using Custom Controllers

I think that I am meeting all of the criteria for this to pass, but when I submit the challenge it gives the following:

Challenge Not yet complete... here's what's wrong: 
Case records were not returned upon calling 'getNewCases'. Either the method does not exist, or it does not return the expected list of cases

Here is the challenge

Create a Visualforce page that uses a custom controller to display a list of cases with the status of 'New'.
  • The page must be named 'NewCaseList'.
  • The custom controller Apex class must be named 'NewCaseListController'.
  • The 'NewCaseListController' Apex class must have a publically scoped method named 'getNewCases'.
  • The 'getNewCases' Apex method should have the return type of 'List' and return a list of case records with the ID and CaseNumber fields and filtered to only have a status of 'New'.
  • The 'NewCaseList' Visualforce page must use an apex:repeat component which is bound to 'newCases'.
  • The apex:repeat component must refer to the var attribute as 'case'.
  • Within the apex:repeat component, bind a apex:outputLink component to the ID of the case so that the page directs the user to the detail page of the respective case record.
Here is my page:
 
<apex:page controller="NewCaseListController">
    <apex:form >
        <apex:pageBlock title="Cases List" id="cases_list">
            
        <!-- Contacts List -->
        <apex:repeat value="{! newCases }" var="case">
            <p>
            	<apex:outputLink value="/{! case.Id }">{!case.CaseNumber}
            	</apex:outputLink> 
            </p>
        
            
        </apex:repeat>

        </apex:pageBlock>
    </apex:form>
</apex:page>

Here is my controller:
 
public class NewCaseListController {
    public static List<Case> getNewCases(){
        List<Case> cases = [SELECT Id, CaseNumber
                           FROM CASE
                           WHERE Status = 'New'];
    	return cases;
    }

}

What am I doing wrong on this? When I preview the page, it seems to be displaying what I would expect. If I change a status from new to something else, it disappears. 
Vishwajeet kumarVishwajeet kumar
try to use :
public class NewCaseListController {
    public List<Case> getNewCases(){
        List<Case> cases = [SELECT Id, CaseNumber
                           FROM CASE
                           WHERE Status = 'New'];
    	return cases;
    }

}

it should work.
Rupal KumarRupal Kumar
Hi Ben ,
Try this code-
Page-

<apex:page controller="NewCaseListController">
  <apex:repeat value="{!newCases}" var="Case">
<li>
<apex:outputLink value="/{!Case.Id}">
  {!Case.CaseNumber}
  </apex:outputLink>
</li>
      
  </apex:repeat>
  
</apex:page>

Controller Class:-

public class NewCaseListController {

    public  List<Case> getNewCases()
    {
        List<Case> caseList = new List<Case>();
        for(Case ct: [Select Id, CaseNumber FROM Case WHERE Status = 'New'])
            caseList.add(ct);

        return caseList;
    }
}

Thanks
Rupal kumar
http://mirketa.com
Shrey VardhanShrey Vardhan
the only difference i see is the use of keyword static keyword in the method. Can someone please explain what exactly does static keyword does in this particular case as the output we get on running the page is appropriate irrespective of 'Static', something happens because of which the challenge fails when we use static.