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
GhanashyamGhanashyam 

How to read the Cases list?

Hi,
The following is a snippet of code I got from the VisualForce manual.
public class dataTableCon {
    List<Account> accounts;
    public List<Account> getAccounts() {
        if(accounts == null) accounts = [select name, owner.name from account];
        return accounts;
    }
}
 
I understand that the method getAccounts() reads the account information and stores them in an account list namely accounts.
 
Similarly is it possible to read a list of 'case' information and store them in a case list? I mean... can someone tell me the equivalent of the below code... I tried the same and it didn't work:(!
 
public class dataTableCon {
    List<Case> cases;
    public List<Case> getCases() {
        if(cases == null) cases = [select CaseNumber, ContactId from Case];
        return cases;
    }
}
 
Many thanks
 
 
Ghanashyam
 
Ron HessRon Hess
your code should work, can you describe the failure that led you to conclude that it did not work?

how did you test it?
do you have any cases?

GhanashyamGhanashyam
You are right Ron. This code works. It was a data error! Thanks anyway:)