SOSL[0]

Issue #895 resolved
Derek Wiers created an issue

Hey there! Minor to moderate issue - it's my first dive into SOSL, and I found the following:

Search.query() or a hardcoded SOSL using square brackets both return List<List<SObject>>. If the query returns no results, then the outer list length will be the number of returning objects and the inner will be empty (but not null) so the following should be safe (and it does compile):

Screen Shot 2018-02-23 at 2.46.29 PM.png

IJ/IC says that it's an illegal conversion from List<List<SObject>> to List<SObject>, since the variable "contacts" in this context is a List<SObject>. However when I replace [0] with .get(0):

Screen Shot 2018-02-23 at 2.46.11 PM.png

There are no issues.

Comments (3)

  1. Scott Wells repo owner

    Turns out this was a more insidious issue than it seemed at first. The following also causes the issue:

    List<List<SObject>> results = new List<List<SObject>>();
    List<Contact> contacts = results[0];
    

    Basically when you index into a list of lists, it was incorrectly inferring a data type of List<ElementType>[] instead of List<ElementType>.

    Thanks for bringing this to my attention! Fix submitted for inclusion in the next build.

  2. Log in to comment