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
MedhanieHabteMedhanieHabte 

Creating & Using Custom Controllers Trailhead Challenge Issue?

Greetings, I cannot seem to get this to work. I have my var set to cs, as it only works with that, rather, as I attempt to set it, I get the error message of var not set correctly. Please advise. Here's the code. The apex code appears correct.

<apex:page controller="NewCaseListController">
    <apex:form >
        <apex:pageBlock title="Case List" id="Case_list">
         <apex:repeat value="{!NewCases}" var="cs">
         <table style="width:1000px;">
          
<tr>
 <apex:repeat value="{!NewCases}" var="cs">
        <apex:outputLink value="https://na16.salesforce.com/{!cs.Id}">{!cs.CaseNumber}</apex:outputLink>
         <apex:outputLink value="{!cs.CaseNumber}">{!cs.CaseNumber}</apex:outputLink>
        </apex:repeat> 
             </tr>
        </table>
             </apex:repeat>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Sandeep BhanotSandeep Bhanot
Hi,
One of the challenge requirements is: "The apex:repeat component must refer to the var attribute as 'case'.".
If you change your var to 'case' instead of 'cs' you should be able to pass the challenge. Thanks and hope this helps.
Sandeep
Nilesh R KhandgeNilesh R Khandge
Hello,

Please try below for this chanllenge

<apex:page controller="NewCaseListController">
    <apex:form >
        <apex:pageBlock title="Case List" id="Case_list">
         <apex:repeat value="{!NewCases}" var="case">
         <table style="width:1000px;">
          
<tr>
 <apex:repeat value="{!NewCases}" var="case">
           <apex:outputLink value="https://ap2.salesforce.com/{!case.Id}">{!case.CaseNumber}</apex:outputLink>
         <apex:outputLink value="{!case.CaseNumber}">{!case.CaseNumber}</apex:outputLink>
        </apex:repeat>
             </tr>
        </table>
             </apex:repeat>
        </apex:pageBlock>
    </apex:form>
</apex:page>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public with sharing class NewCaseListController {

    public List<Case> getNewCases()

     {
       List<Case> results =Database.query('SELECT ID, CaseNumber FROM Case LIMIT 10');

       return results;

    }
}
Ashit AdhikariAshit Adhikari
Hello...one of the requirements of the challange is to extract only cases with status 'New'. This filter is missing from your code.
Marco Pollastri 1Marco Pollastri 1
Hey All, I just wanted to shere the code that I have created and it was working for me.:

_____________________________________________________________________

Controller - "NewCaseListController"

public class NewCaseListController {

list<case> newcase = new list<case>();
    public list<case> GetNewCases() 
    {
    newcase = [Select Id,CaseNumber from case where status='New'];

        return newcase;
    }
}

_______________________________________________________________________


VF - 'NewCaseList'

<apex:page controller="NewCaseListController">
  <apex:repeat var="case" value="{!NewCases}">
  <li>
  <apex:outputLink value="/{!case.id}">{!case.id}</apex:outputLink>
    {!case.CaseNumber}
  </li>
  </apex:repeat>
</apex:page>

____________________________________________________________________


Marco
 
Jonathan A FoxJonathan A Fox
I understand <apex:outputLink value="https://ap2.salesforce.com/{!case.Id}">{!case.CaseNumber}</apex:outputLink>
but
what does <apex:outputLink value="{!case.CaseNumber}">{!case.CaseNumber}</apex:outputLink> achieve? 
Saket Ranjan 3Saket Ranjan 3
@nilesh in query you need to check for status.

public class NewCaseListController {
public list<case> getNewCases(){
String st='new';
List<case> results = Database.query('select id, CaseNumber from case where status=:st');  //status="new" was giving error sometime

return results;
}
}
Rounak SharmaRounak Sharma

Hello MedhanieHabte,

Please try with the below code:
Page:
<apex:page controller="NewCaseListController">
     <apex:pageblock title="New Cases List" id="cases_list"> 
        <apex:repeat var="case" value="{! newCases }" rendered="true"  id="case_list"  >
            <li>
                <apex:outputLink value="/{!case.ID}" >
                    <apex:outputText value="{!case.CaseNumber}"/>
                </apex:outputLink>
            </li>
        </apex:repeat>        
    </apex:pageblock>
</apex:page>

Controller
public class NewCaseListController {
    private String val = 'New';
    public List<Case> getNewCases() { 
        List<Case> results = Database.query(
            'SELECT Id, CaseNumber FROM Case WHERE Status = \'' + String.escapeSingleQuotes(val)+'\'');
        return results;
    }
}

Please mark it as the best answer if it helps you in any way.

thanks

Ajay K DubediAjay K Dubedi
Hi MedhanieHabte,

As your requirement, I have written this code.You want to find all new cases which status are 'new', right?
Please try once this code.


<apex:page controller="NewCaseListController">
     <apex:pageblock title="All New Cases List" id="all_cases_list"> 
        <apex:repeat var="case" value="{! newCases }" rendered="true"  id="all_cases_list"  >
            <li>
                <apex:outputLink value="/{!case.ID}" >
                    <apex:outputText value="{!case.CaseNumber}"/>
                </apex:outputLink>
            </li>
        </apex:repeat>        
    </apex:pageblock>
</apex:page>


Controller-----------

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

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com 
Monica NadellaMonica Nadella
I'm getting an error in the console that "Unknown property NewCaseListController.case" plz help me