Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i am getting an error given below while i trying to iterate a List of String lists. I am thinking that i missed something very simple but did not able to move beyond this issue. Please clarify.

Save error: Loop variable must be of type LIST

List<List<String>> lstResp = new List<List<String>> {};
lstResp = Utility.ParseMultipleResponse(ret);
for(List<List<String>> n: lstResp) { //error line 
   for(List<String> l: n) {
     //-------some code here-------------
share|improve this question
up vote 9 down vote accepted

Hopefully these names help explain what is going on:

List<List<String>> listOfListOfString = Utility.ParseMultipleResponse(ret);
for (List<String> listOfString : listOfListOfString) {
    for (String str : listOfString) {
        // Code

Each for loop iterates over a list, so the type of the for loop variable is "one list less" in each case.

share|improve this answer
Thanks @Keith. I understood the issue now based on your explanation. – Baskaran S May 5 '14 at 17:43

Your list is type of List<String>. So an element is type of that. Your for loop should be something like,

for(List<String> firstList: lstResp) { 
   for(String singleString : firstList){
   // Some code
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.