You need to sign in to do that
Don't have an account?
Jonathan 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:
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; } }
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:
If this information helps, please mark the answer as best. Thank you
All Answers
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:
If this information helps, please mark the answer as best. Thank you
Following up to see if the above code change worked for you or no. Thanks