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
lauraecilauraeci 

SOSL Help needed: System.QueryException: unexpected token: FIND

Hi!

 

The the same query that works in the workbench fails running in Salesforce:

 

System.QueryException: unexpected token: FIND

 

Any help is appreciated!

 

Thanks!

Laura

 

The object eci_HTTPEventLog__c contains the following:

eci_HTTPEventLog__c.response__c = '<Envelope><Body><RESULT><SUCCESS>true</SUCCESS<SESSIONID>349557C0E497DDFC154379B4DF528057</SESSIONID><ORGANIZATION_ID>5872ae98-1341ac53619-d7c8ec57ae636c7258d3eb0ef0e531f2</ORGANIZATION_ID<SESSION_ENCODING>;jsessionid=349557C0E497DDFC154379B4DF528057</SESSION_ENCODING</RESULT></Body></Envelope>';

 

 

            String response = '';

            

            String queryString = 'FIND {jsessionid} IN ALL FIELDS RETURNING eci_HTTPEventLog__c';  // fails here

            

            for (LIST<SObject> sobj : database.query(queryString)) {

              for (SObject objs : sobj) {

                  

                if (objs.getSObjectType() == eci_HTTPEventLog__c.sObjectType)

                {

                  eci_HTTPEventLog__c event = (eci_HTTPEventLog__c) objs;

                  response = event.response__c;

                }

              }

            }

Best Answer chosen by Admin (Salesforce Developers) 
ShamilShamil

Use search.query() instead of database.query(), as the latter expects a SOQL query, not SOSL.

Example:

 

String searchquery='FIND\'ge*\'IN ALL FIELDS RETURNING Account(id,name)'; 
List<List<SObject>>searchList=search.query(searchquery);
List<Account> accounts = (List<Account>) searchList[0];