0

Let's say I have several different lists of objects:

typeA[] Alist = [ ... ];
typeB[] Blist = [ ... ];
typeC[] Clist = [ ... ];

And I want to perform the same operation on each list:

for (List<SObject> xx : [ Alist, Blist, Clist ]) {
    doTheThing(xx);
}

What is the correct syntax?

1 Answer 1

3

You'd start with a list of lists:

List<List<sObject>> allLists = new List<List<sObject>> { Alist, Blist, Clist };
for(List<sObject> xx: allLists) {
  doTheThing(xx);
}

You can also do that inline:

for(List<sObject> xx: new List<List<sObject>> { Alist, Blist, Clist }) {
  doTheThing(xx);
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .