You need to sign in to do that
Don't have an account?

List of Lists, need help is looping through each list in the master list
I have created a list of lists. What I need to do now is to loop through each of the inner loops.
Here is my code so far:
List<List<SFDC_Schedule__c>> allSchedules = new List<List<SFDC_Schedule__c>>();
List<SFDC_Schedule__c> tempList = new List<SFDC_Schedule__c>();
for (SFDC_Schedule__c item : [Select id, name, Assigned_Name__c, ServiceDate__c, Total__c, Project__c
From SFDC_Schedule__c
Where ServiceDate__c >: startDate
And ServiceDate__c <: endDate
And Project__c <> null
Order By Assigned_Name__c, ServiceDate__c])
{
tempList.add(item);
if (tempList.size() == 10)
{
allSchedules.add(tempList);
tempList.clear();
}
}
if (tempList.size() > 0)
{
allSchedules.add(tempList);
tempList.clear();
}
Then trying to loop through the lists inside the master list:
list<sfdc_schedule__c> LoopList = new list<SFDC_Schedule__c>();
system.debug('helloworld1 ' + allSchedules.size());
for(integer i = 0; i < allSchedules.size(); i++)
{
system.debug('helloworld2 ' + i);
LoopList = new list<SFDC_Schedule__c>();
LoopList = allSchedules[i];
system.debug('helloworld3 ' + LoopList.size());
for(integer v = 0; i < LoopList.size(); v++)
{
system.debug('helloworld4 ' + LoopList[v].Project__c);
}
}
helloworld1 is showing 11 (which means there are 12 lists inside the master list
helloworld2 is displaying the numbers 0 thru 11
helloworld3 is always displaying 0.
helloworld4 is NEVER being hit.
I know I am missing something very basic here. Any help would be great.
Thanks
--Todd Kruse
Hello Todd;
Try changing the line
allSchedules.add(tempList);
as below
allSchedules.add(tempList.deepClone());
Sometimes you may need to change the line
for(integer v = 0; i < LoopList.size(); v++)
as
for(integer v = 0; v < LoopList.size(); v++)
Thanks for the advice. I have made those changes and my report is now generating in our staging environment to perfection. However, when I go to validate it against production, I receive the message:
Too many script statements: 200001.
What I am doing is, I have a master list (approx 75 records in it). for each of those records in that list, I loop through all of the lists in the list (because the <list<list is returning around 5000 records, too big for one list).
--Todd Kruse