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
Jonathan Wolff 7Jonathan Wolff 7 

Error: Method does not exist or incorrect signature: void query(List<List<SObject>>) from the type Database

Hello, I tried to create a sosl spex class, but get the error: Method does not exist or incorrect signature: void query(List<List<SObject>>) from the type Database

My code is the following:
 
public class MediathekSearchController2 {

    
    @AuraEnabled(cacheable=true)
    public static List<List<sObject>> getSearchResult(String searchKey, String TypValue, String ZielgruppeValue, String ThemaValue){
        String findStr = '*'+searchKey+'*';
        
        Boolean isEmptySearch = String.isEmpty(searchKey);
        
       system.debug('Das searchKey ist: ' + findStr);
      List<List<SObject>> searchResult2 = [FIND :findStr IN ALL FIELDS RETURNING Mediathek__c (Id,  Thema__c, Mediathek_ID_Long__c, Name, Bezeichnung__c, ContentDocumentID__c, Typ__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c WHERE Inaktiv__c=false)];
    
        system.debug('Das searchResult2 ist: ' + searchResult2);
      
   
   List<List<sObject>> searchResult = Database.query(searchResult2);
 	
	system.debug('searchKey ' + searchResult); 
    
     return searchResult;
    }
       }



 
Best Answer chosen by Jonathan Wolff 7
SwethaSwetha (Salesforce Developers) 
HI Jon,
I see that you are passing a variable of type List<List<sObject>> to the Database.query method, which is not a valid argument.

Based on https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm, the Database.query method expects a single String argument that contains a valid SOQL query. The FIND clause used in your code is specific to SOSL (not SOQL), so it cannot be used directly in a Database.query call.

To fix the error, you can remove the Database.query line and just return the searchResult2 variable directly:
public static List<List<sObject>> getSearchResult(String searchKey, String TypValue, String ZielgruppeValue, String ThemaValue){
    String findStr = '*'+searchKey+'*';
    Boolean isEmptySearch = String.isEmpty(searchKey);
    
    system.debug('Das searchKey ist: ' + findStr);
    List<List<SObject>> searchResult2 = [FIND :findStr IN ALL FIELDS RETURNING Mediathek__c (Id,  Thema__c, Mediathek_ID_Long__c, Name, Bezeichnung__c, ContentDocumentID__c, Typ__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c WHERE Inaktiv__c=false)];
    
    system.debug('Das searchResult2 ist: ' + searchResult2);
    
    return searchResult2;
}

If this information helps, please mark the answer as best. Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Jon,
I see that you are passing a variable of type List<List<sObject>> to the Database.query method, which is not a valid argument.

Based on https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm, the Database.query method expects a single String argument that contains a valid SOQL query. The FIND clause used in your code is specific to SOSL (not SOQL), so it cannot be used directly in a Database.query call.

To fix the error, you can remove the Database.query line and just return the searchResult2 variable directly:
public static List<List<sObject>> getSearchResult(String searchKey, String TypValue, String ZielgruppeValue, String ThemaValue){
    String findStr = '*'+searchKey+'*';
    Boolean isEmptySearch = String.isEmpty(searchKey);
    
    system.debug('Das searchKey ist: ' + findStr);
    List<List<SObject>> searchResult2 = [FIND :findStr IN ALL FIELDS RETURNING Mediathek__c (Id,  Thema__c, Mediathek_ID_Long__c, Name, Bezeichnung__c, ContentDocumentID__c, Typ__c, Zielgruppe__c, Umfang__c, Bezeichnung_Link__c, Bezeichnung_Search__c WHERE Inaktiv__c=false)];
    
    system.debug('Das searchResult2 ist: ' + searchResult2);
    
    return searchResult2;
}

If this information helps, please mark the answer as best. Thank you
This was selected as the best answer
SwethaSwetha (Salesforce Developers) 
HI Jon,
Following up to see if the above code change worked for you or no. Thanks