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
ShuchiMShuchiM 

SOSL query error

Hi All,

 

I am trying to create a search function in apex that contains SOSL. Here's my query :

String searchQry = 'FIND '\' ' + searchText +  '\' ' ;

List<List<SObject>> searchList = search.query(searchQry);

 

However, i am getting an error - "Entities should be explictly specified in SOSL call in Apex". I do not want to specify the objects coz i want it to search all objects. According to the documentation, the RETURNING Clause is optional - http://www.salesforce.com/us/developer/docs/soql_sosl/index.htm.

 

If i add the object, the error goes away. Please help !

 

Regards

Shuchi

Jia HuJia Hu
You can search 'all fields', but not all objects.

You can search multiple objects at the same time, but not all.
ShuchiMShuchiM

So do i have to specify the objects in the query ? I thought it was optional. Can you give me an example?


Jia Hu wrote:
You can search 'all fields', but not all objects.

You can search multiple objects at the same time, but not all.

 

vishal@forcevishal@force

Can you share your SOSL query? That would be simpler to understand the issue.

ShuchiMShuchiM

I did:

 

String searchQry = 'FIND '\' ' + searchText +  '\' ' ;

List<List<SObject>> searchList = search.query(searchQry);

 

 

searchText is anything like '000410' or 'ThinkGeek'.

Srinivasaragavan JayakumarSrinivasaragavan Jayakumar
When you Use it in apex,  the RETURNING Clause is not optional. When you use it in dev console this is optional. So you need to specify the Retrurning clause with the list of objects that you would like to search.
list<list<sobject>> result = [
    FIND:'Mission Specialist'
    IN ALL FIELDS
    RETURNING Contact (FirstName, LastName)
    
];
 
WendyFWendyF
Thanks!  The Trailhead module did not make this clear.