You need to sign in to do that
Don't have an account?
Greg Coogan
Access Records in a List of Lists in a Test Class
I have a custom Visualforce page and Controller that returns some records and related records. As part of the query, I put the related records in a List that is used in DataRow on the Visualforce page.
For writing my Test Class, I have code coverage, but cannot actually assert that I'm getting the correct data back. I beleive it is due to using of List of Lists in my Controller.
Here is code where I build the List of Lists in my Controller that has been anonymized:
How can I access the list of related records in my Test Class? I want to assert that my related test record was returned by the query. In my example, I am referring to the "somerecords" list which represents records from an object that is related to the custom case object.
For writing my Test Class, I have code coverage, but cannot actually assert that I'm getting the correct data back. I beleive it is due to using of List of Lists in my Controller.
Here is code where I build the List of Lists in my Controller that has been anonymized:
public class MyController { public class Lists{ public CustomCase__c someCase{get;set;} public List<CustomObjectB__c> somerecords{get;set;} public Lists(){ this.someCase = new CustomCase__c(); this.somerecords = new List<CustomObjectB__c>(); } } public List<Lists> lstList{get;set;}I add records, including related records, to the lists in the following code:
public void getStuff(){ query = 'Select Some Data' //Execute query transient List<CustomCase__c> lstCases = Database.query(query); //If any cases are returned, build lists of related records for each case returned. These lists are used on the Visualforce page. if(lstCases.size()>0){ for(CustomCase__c someCase:lstCases){ Lists lst = new Lists(); lst.someCase = someCase; if(someCase.somerecords__r.size() > 0){ lst.somerecords = someCase.somerecords__r; } lstList.add(lst); } } }When I access "lstList" in my test class, it returns "MyController$Lists."
How can I access the list of related records in my Test Class? I want to assert that my related test record was returned by the query. In my example, I am referring to the "somerecords" list which represents records from an object that is related to the custom case object.