+ Start a Discussion
SuAkSuAk 

Trailhead:Create a Visualforce page displaying new cases

Hi,

Given below are the code for my custom controller :

public class NewCaseListController //{get;private set;}//
{
     public List<case> getNewCases(){
     List<case>results = Database.query(
            'SELECT Id, CaseNumber, Status ' +
            'FROM Case ' +
           'WHERE Status = \'New\' '
        );
    return results;
    }
}

Given below are the code for my visualforce page : 

<apex:page controller="NewCaseListController">
<apex:pageBlock title="New Cases">
      <apex:repeat var="case" value="{!cases}" id="new_cases"><br/>
       <apex:outputLink value="/{!case.id}">{!case.name}</apex:outputLink>
      </apex:repeat>
 </apex:pageBlock>
</apex:page>

I am getting the folloing error : 

Unknown property 'NewCaseListController.cases'

Kindly help.

Thanks,
Sujatha
Amit Chaudhary 8Amit Chaudhary 8
Your code should be like below
<apex:page controller="NewCaseListController">
    <apex:form >
        <apex:pageBlock title="Case List" id="Case_list">
            <!-- Case_list -->
         <apex:repeat value="{!Case}" var="cs">
            <apex:outputLink value="{!cs.Id}">{!cs.Id}</apex:outputLink>
            <apex:outputLink value="{!cs.CaseNumber}">{!cs.CaseNumber}</apex:outputLink>
        </apex:repeat>      
        </apex:pageBlock>
    </apex:form>
</apex:page>
Public class NewCaseListController {
List<Case> results = new List<Case>();


private String sortOrder = 'CaseNumber';
public List<Case> getCase() {
    
    results = [SELECT Id, CaseNumber FROM Case WHERE Status = 'New'];

    return results;
    }
}
https://developer.salesforce.com/forums/?id=906F0000000AzvMIAS

If you want to use your code only then update your VF page like below:-

<apex:page controller="NewCaseListController">
<apex:pageBlock title="New Cases">
      <apex:repeat var="case" value="{!NewCases}" id="new_cases"><br/>
       <apex:outputLink value="/{!case.id}">{!case.name}</apex:outputLink>
      </apex:repeat>
 </apex:pageBlock>
</apex:page>
 
SuAkSuAk
Hi Amit - Thanks for the reply. I tried updating my code as per your suggestion, I got the same error. I also tried with your code, it is the same error again. 

'Unknown property 'NewCaseListController.case'

No clue what is the issue.. Let me know if you have any solution.

Thanks,
Sujatha
Amit Chaudhary 8Amit Chaudhary 8
Please update your code like below :-
VF 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;
    }
}