4

Here is the criteria for the question:

• 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. Controller:

public class NewCaseListController {

    public static 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;
    }
}

VFP:

<apex:page controller = "NewCaseListController" >

    <apex:repeat value ="{!newCases}" var="case">


    </apex:repeat> 

</apex:page>

For some reason my apex:page tags aren't showing up in the code above (I do have them)... the issue is I don't know what to do with the repeat tag (last bullet)

5
  • 1
    value="{! URLFOR($Action.Case.View, case.Id) }" is the wrong answer, but should be the right answer as it actually takes you to the detail case when clicked. value="/apex/{!case.Id}" is the right answer, but doesn't take you to the case detail when clicked. So perhaps they want you to hard code the url up to the id, which is ridiculous because that could change, and it's a temporary dev org, which makes the domain and url even more ridiculous to hardcode. Apr 13, 2019 at 4:39
  • You can also just return directly the list resulted from the query without assigning all values to a list: return [Select Id, CaseNumber FROM Case WHERE status = 'New'];
    – Alberto
    Oct 6, 2021 at 12:11
  • The comment from @kikocarisse is the correct answer; I just validated it myself. Someone should move it from a Comment to an Answer and upvote it as such.
    – Bane
    Apr 24 at 16:34
  • 1
    @Bane I'd move it myself, but I need 10 more reputation points to create real answers. I don't have any real reputation points in the Salesforce stack exchange, yet, sadly. I appreciate you calling out the answer, I hope that causes it to help more people! Feel free to make it your answer if you have the Reputation points. Maybe put @ tag me on the answer if you want. Apr 25 at 18:11
  • 1
    @kikocarisse Sadly I also don't have the rep here to make my own answers :) -- maybe Ratan Paul could do it
    – Bane
    Apr 26 at 19:42

2 Answers 2

3

Here's part of what you need to sort out. What's the code you'd use to display a single record containing the ID and CaseNumber fields from the list that's returned? You need to encapsulate that code for displaying those fields within your repeat tags using the value assigned to var; the latter being something you've not done correctly.

I recommend you refer to the links provided you in the references given in the challenge. Having gone through Trailhead myself, they generally give you most everything you need either in the module itself or in the references they point you to just above where the challenge begins.

1
  • 1
    This is answer is not exactly correct. Outside of the particular Trailhead-question, it definitely is; however, in context of that question, it is not. That is because the Trailhead-question that is being asked about is expecting an incorrect answer, while this response is only general best-practice but is not actually answering the question. I wanted to highlight that for other readers. The answer here is how you should write your code; but it will not help you pass the particular Trailhead question being discussed. Refer to the comment from @kikocarisse instead.
    – Bane
    Apr 24 at 16:30
1

First of all you need to correct your apex class public static List getNewCases() should not be static while you return is caseList.it will Resolve the (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) error. And second thing for apex:page is that you have to add any input/output Field in repeat tag like --( apex:outputLink value="/{!Case.Id}"> {!Case.Id} ) (please add the right and left angle bracket(<,/>) in input/output field as requirement needed)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .