+ Start a Discussion
Carlton BrumbelowCarlton Brumbelow 

Query results in class not showing on Visualforce page

Hi, I'm trying to use an apex class to query the database and display the results on a visualforce page. The class (and page) saves without error, but nothing displays on the page when I navigate there. I'm new to this and know what's missing is likely very simple, but any help would be appreciated.

Here's the class:
public class SSReportTest {
    public String casenumber = 'JAMF-0160404';
    public List<sObject> numberList {get; set;}
    
    public List<sObject> getList() {
        numberList = Database.query('SELECT Case.Owner from Case where Case.CaseNumber = "J-0160404"');
        return numberList;

    }
}
And here is the visualforce page:
<apex:page controller="SSReportTest">
    
    <apex:pageBlock >
        {!numberList}
    </apex:pageBlock>
    
</apex:page>

Thanks everyone!
 
Best Answer chosen by Carlton Brumbelow
Ankit SehgalAnkit Sehgal
public class SSReportTest
{
      public String casenumber = 'JAMF-0160404';
      public List<sObject> getList()
      {
            List<sObject> numberList = Database.query('SELECT OwnerId from Case where CaseNumber =: casenumber');
            return numberList;
      }
}



<apex:page controller="SSReportTest">
<apex:pageBlock>
<apex:pageBlockTable  value="{!List}" var="numlist">
          <apex:column value="{!numlist.OwnerId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>


if your page still doesn't shows any value then case number might be wrong.

All Answers

Shikha AgashiShikha Agashi
<apex:page controller="SSReportTest">
    
    <apex:pageBlock value="{!numberlist}"  var="numlist">
       <apex:column value="{!numlist.Case.Owner}"/>

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

Try above code in VF Page
Ankit SehgalAnkit Sehgal
public class SSReportTest
{
      public String casenumber = 'JAMF-0160404';
      public List<sObject> getList()
      {
            List<sObject> numberList = Database.query('SELECT OwnerId from Case where CaseNumber =: casenumber');
            return numberList;
      }
}



<apex:page controller="SSReportTest">
<apex:pageBlock>
<apex:pageBlockTable  value="{!List}" var="numlist">
          <apex:column value="{!numlist.OwnerId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>


if your page still doesn't shows any value then case number might be wrong.
This was selected as the best answer
Carlton BrumbelowCarlton Brumbelow
Hi Ankit,

Thank you for attempting to help. I think we're close, but when I attmempt to save the visualforce page the error I'm receiving now is:

"Unknown Property: SObject.Owner"

Any ideas? I'll have some time in a bit to do my own research as well.

Thanks!
Carlton BrumbelowCarlton Brumbelow
Thank you Ankit. Your suggestions helped. I still needed to change the object type for SObject to Case. Once I did that though, everything worked. Thanks again!
Carlton BrumbelowCarlton Brumbelow
Would you, or anyone else, mind explaining one part here that I don't understand though? We name the function getList() and in that function we name a variable numberList.

However, in the visualforce page we set the value of the PageBlock to !List. Why?

When I try changing list to !numberList I am told that there is no property of SSReportTest.numberList. I'm not making the conneciton as to why it's working as it currently is.
Ankit SehgalAnkit Sehgal
"get" keyword before the function name implies that it is a get property i.e the values are bieng provided to the value attribute.
we can also define get property as follows.
List<Case> calselist{ get{ list<case> cl=[SELECT CaseNumber FROM Case]; 
                                      return cl;}}
or define a function 
list<case> getcaselist() { list<case> cl=[SELECT CaseNumber FROM Case]; 
                                            return cl; }
both will have the same functionality. The list variable "cl" in this case is independent and can be named anything.

The reason {!numberList} was unaccessible was because it was local to the getList() property.To make it accessible you will have to declare another property getnumberList{}.