function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jen BranJen Bran 

Illegal assignment from List to List - No Class of same name issue

At this point I'm spinning my wheels and need to call on the experts.  I am pulling a list of Strings from SOQL and trying to put them in a String List, but not matter what method I use I always seem to end up with "Illegal assignment from List to List."  Once the list is populated, I want to use it and loop through each value and query a table for records that have the value.  Basically a series of events occur for each value in the string list.  All of the posts on line seem to be saying I have a class of the same name (nope) or I'm using a field when I need a list or something.  None of that seems accurate.  So why else would I be getting this error?  I've tried a lot of different methods to do the list and they all work up to a point, but then I try to use the values and I hit a wall and that error pops up.  Help!

In an nutshell (not actual code)

List<String> test = [Query from System]

for(Integer i=0; i< test.size(); i++){
   for (List<Case> cas : [Query from System where field = test[i]]{
        for(Case c: cas){
           str += c.CaseNumber + ',' + c.CustomField__c;
    }
   //do something with str
  }
}
Best Answer chosen by Jen Bran
_Zach Boyd_Zach Boyd
Most likely you need to actually have the List parameterized type represent the object you are querying and then reference the string property. Here is an example using the code above. Let me know if this helps! If not, could provide the real query and then I could point you in the right direction.
 
List<MyObject> test = [SELECT MyString from MyObject];

for(Integer i=0; i< test.size(); i++){
   for (List<Case> cas : [Query from System where field = test[i].MyString]{
        for(Case c: cas){
           str += c.CaseNumber + ',' + c.CustomField__c;
    }
   //do something with str
  }
}

 

All Answers

_Zach Boyd_Zach Boyd
Most likely you need to actually have the List parameterized type represent the object you are querying and then reference the string property. Here is an example using the code above. Let me know if this helps! If not, could provide the real query and then I could point you in the right direction.
 
List<MyObject> test = [SELECT MyString from MyObject];

for(Integer i=0; i< test.size(); i++){
   for (List<Case> cas : [Query from System where field = test[i].MyString]{
        for(Case c: cas){
           str += c.CaseNumber + ',' + c.CustomField__c;
    }
   //do something with str
  }
}

 
This was selected as the best answer
_Zach Boyd_Zach Boyd
I accidentally put the MyString reference in bold above which is why you see the <b> tags so just ignore those.
Jen BranJen Bran
Thank you! I'd been through so iterations trying to get it to work that I missed that I had changed that.
_Zach Boyd_Zach Boyd
Your welcome! Would you be able to mark as correct so that others may reference in the future?