-2

trying to populate a map with a list list like this:

map<integer , listlist<<sobject>>> mpsosl=[find ' ba' IN all Fields RETURNING contact(name)];

error:Illegal assignment from List<List> to Map<Integer,List<List>>

2 Answers 2

3

Looks like your syntax is the issue from what you've shared. Nested collections like a List of Lists are possible within Apex, but it would be defined like this: List<List<Contact>> or even something like List<List<Set<Integer>>>.

Your SOSL query will return a List<List<SObject>>. I would recommend assigning your results to a List<List<SObject>>, and then put it into your map.

List<List<SObject>> mpsosl = [
    FIND ' ba' 
    IN All Fields 
    RETURNING Contact(name)
];
Map<Integer, List<List<SObject>> numToListOfList = new Map<Integer, List<List<SObject>>();
numToListOfList.put(1, mpsosl);
0

The return type of a SOSL is a List of List of SObjects. So, you should use -

List<List< SOject >> mpsosl=[find ' ba' IN all Fields RETURNING contact(name)];

Because of this you are getting the illegal assignment error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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