Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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
add comment

2 Answers 2

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 at 17:43
add comment

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
add comment

Your Answer

 
discard

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.