Here's a for loop I have in my code, which loops through a list of account IDs. It takes each ID and puts it as the first element of a new list. That list is then populated with additional IDs (Populate_All_Children(list)), after which it is inserted into a list of lists ("accGroups_List").
for(ID startID :accID_List){
List<ID> tempList = new List<ID>();
tempList.add(startID);
Populate_All_Children(tempList);
accGroups_List.add(tempList);
}
I learned from a recent question that lists are passed by reference, which has me wondering whether I'm actually creating a new, separate tempList variable for each iteration of the loop - or if instead the same list is being constantly overwritten.
The goal is to create a new list for each iteration - I'd name each tempList differently if I knew how. What I dont want is for accGroups_List to be filled with pointers to the same list data, which would come from the very last iteration.
Will my code get me what I want?