You need to sign in to do that
Don't have an account?
Creating & Using Custom Controllers Challenge problem
I have been able to get similar ones to work (based on prior challenges) but I am struggling here. Probably a newbie mistake somewhere. Any help would be appreciated! Thanks, Aron
-> Page (Gives Error: Unknown property 'String.Id error)
<apex:page controller="NewCaseListController">
<apex:form >
<apex:pageBlock title="Case List" id="Case_list">
<!-- Case_list -->
<apex:repeat value="{!Case}" var="case">
<apex:outputLink value="{!Case.Id}">{!Case.Id}</apex:outputLink>
<apex:outputLink value="{!case.CaseNumber}">{!case.CaseNumber}</apex:outputLink>
</apex:repeat>
</apex:pageBlock>
</apex:form>
</apex:page>
-> Class
ublic class NewCaseListController {
public String getCase() {
return null;
}
public String getCases() {
return null;
}
private String sortOrder = 'CaseNumber';
public List<Case> getNewCases() {
List<Case> results = Database.query(
'SELECT Id, CaseNumber ' +
'FROM Case ' +
'WHERE Status = New ' +
'ORDER BY ' + sortOrder + ' ASC ' +
);
return results;
}
}
-> Page (Gives Error: Unknown property 'String.Id error)
<apex:page controller="NewCaseListController">
<apex:form >
<apex:pageBlock title="Case List" id="Case_list">
<!-- Case_list -->
<apex:repeat value="{!Case}" var="case">
<apex:outputLink value="{!Case.Id}">{!Case.Id}</apex:outputLink>
<apex:outputLink value="{!case.CaseNumber}">{!case.CaseNumber}</apex:outputLink>
</apex:repeat>
</apex:pageBlock>
</apex:form>
</apex:page>
-> Class
ublic class NewCaseListController {
public String getCase() {
return null;
}
public String getCases() {
return null;
}
private String sortOrder = 'CaseNumber';
public List<Case> getNewCases() {
List<Case> results = Database.query(
'SELECT Id, CaseNumber ' +
'FROM Case ' +
'WHERE Status = New ' +
'ORDER BY ' + sortOrder + ' ASC ' +
);
return results;
}
}
I'm not an expert, but I made some modifications, it seems to complile for me, but I haven't tested it, because we don't use cases.
Note, I removed your sort order because I wasn't sure what you wanted to sort by. Ie it should be ORDER By Name ASC etc
Also, there shouldn't be a + after ASC because there's nothing else there.
Hope this helps.
All Answers
I'm not an expert, but I made some modifications, it seems to complile for me, but I haven't tested it, because we don't use cases.
Note, I removed your sort order because I wasn't sure what you wanted to sort by. Ie it should be ORDER By Name ASC etc
Also, there shouldn't be a + after ASC because there's nothing else there.
Hope this helps.
For example, from the page case id shows 500j0000001XPSTAA4 and takes you to this link
https://c.na16.visual.force.com/apex/500j0000001XPSTAA4
Case number 0001063 takes you here
https://c.na16.visual.force.com/apex/00001063
Neither of these pages work, the The correct link
https://na16.salesforce.com/500j0000001XPST
Let me know if you have time!
CURRENTLY HAVE:
<apex:page controller="NewCaseListController">
<apex:form >
<apex:pageBlock title="Case List" id="Case_list">
<!-- Case_list -->
<apex:repeat value="{!NewCases}" var="case">
<table style="width:1000px;">
<tr>
<BR><span style="margin-left:20px"> </span><apex:outputLink value="{!case.Id}" style="width:160px">{!case.Id}</apex:outputLink>
<span style="margin-left:20px"> </span><apex:outputLink value="{!Case.CaseNumber}" style="width:160px" >{!case.CaseNumber}</apex:outputLink></BR>
</tr>
</table>
</apex:repeat>
</apex:pageBlock>
</apex:form>
</apex:page>
NOTES ON MY CHANGES:
Trailhead said:
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
I changed:
Page <apex:repeat value="{!NewCases}" var="cs">
Apex public List<Case> getNewCases() {
Trailhead said"
Challenge not yet complete... here's what's wrong:
The repeat component does not have the var attribute set correctly
I changed to
<apex:repeat value="{!NewCases}" var="case">
<apex:outputLink value="{!case.Id}">{!case.Id}</apex:outputLink>
<apex:outputLink value="{!case.CaseNumber}">{!case.CaseNumber}</apex:outputLink>
So that means the URL needs to be something like ?Id=500j0000001XPSTAA4
Then you can add in the following to get the ID into the class
And then adjust the SQL query to include the ID
When I try this code the page just says Case List at the top and nothing below. Do I need to edit the page as well?
private String sortOrder = 'CaseNumber';
public List<Case> getNewCases() {
Id PlanId = ApexPages.currentPage().getParameters().get('id');
results = [SELECT Id, CaseNumber FROM Case WHERE id = :planId];
return results;
}
}
?Id=500j0000001XPSTAA4
<apex:column headerValue="Product Code">
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">
{!a.ProductCode}
</apex:outputlink>
</apex:column>
Public class NewCaseListController {
List<Case> results = new List<Case>();
private String sortOrder = 'CaseNumber';
public List<Case> getNewCases() {
results = [SELECT Id, CaseNumber FROM Case WHERE status = 'new'];
return results;
}
}
_____________________
<apex:page controller="NewCaseListController">
<apex:form >
<apex:pageBlock title="Case List" id="Case_list">
<!-- Case_list -->
<apex:repeat value="{!NewCases}" var="case">
<table style="width:1000px;">
<tr>
<BR><span style="margin-left:20px"> </span><apex:outputLink value="{!case.Id}" style="width:160px">{!case.Id}</apex:outputLink>
<span style="margin-left:20px"> </span><apex:outputLink value="{!Case.CaseNumber}" style="width:160px" >{!case.CaseNumber}</apex:outputLink></BR>
</tr>
</table>
</apex:repeat>
</apex:pageBlock>
</apex:form>
</apex:page>
After speding quite a bit of time on this myself.
1. Please do not hardcode your instance as this may change.
2. The repeat component needs:Value, Var and ID.
3. Filter on New to 'WHERE Status = \'New\' '
So thats is how would work and pass the badge:
VISUALFORCE PAGE NewCaseList
CUSTOM CONTROLLER NewCaseListController
Tada!
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;
}
}
VF Page:
<apex:page controller="NewCaseListController" >
<apex:pageblock title="New status Cases">
<apex:repeat value="{!newCases}" var="case">
<li>
<apex:outputLink value="/{!case.id}">{!case.id} </apex:outputLink>
{!case.casenumber}
</li>
</apex:repeat>
</apex:pageblock>
</apex:page>
Controller:
public class NewCaseListController {
public List<case> getNewCases()
{
list<case>newcase =[select id,casenumber from case where status='new'];
return newcase;
}
}
Custom Controller
VisualForce Code
private String sortOrder = 'CaseNumber';
private String sortOrder = 'CaseNumber';
I've tried everything you all said, nothing works for me, can't complete the challenege...
Same message over and over : The method 'getNewCases' isn't working as expected. Either the method doesn't exist or it doesn't return the expected list of cases
I tried deleting cookies, deleting and recreating both VFpage and Controller.
I tried Ani gho's code, Akshay Koparde's code, praveen jha 36's code, no success...
I wonder what it can be...If you have any idea, thanx !
<apex:form >
<apex:pageBlock title="Case List" id="Case_list">
<!-- Case_list -->
<apex:repeat value="{!newCases}" var="case">
<p>
<apex:outputLink value="https://resilient-hawk-rqs1tj-dev-ed.lightning.force.com/lightning/r/Case/{!case.Id}/view">{!case.CaseNumber}</apex:outputLink>
</p>
</apex:repeat>
</apex:pageBlock>
</apex:form>
</apex:page>
List<Case> NewCases = new List<Case>();
public List<Case> getNewCases() {
NewCases = [SELECT Id, CaseNumber FROM Case WHERE Status = 'New'];
return NewCases;
}
}