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
apexdevSunilapexdevSunil 

Not able to execute the SOSL query

Hi

 

I am trying to execute the SOSL query with in Developer Edition of SalesForce.

This is my 3rd post still it is not answered.

 

Here is the code I am trying to execute

 

try

{

 

List<List<SObject>> searchList = [FIND 'Levis' IN NAME FIELDS RETURNING Opportunity(Amount, CloseDate, Name, OwnerId, StageName) LIMIT 1];

Opportunity[] records = (List<Opportunity>)searchList[0];

System.debug('@@@@@ In the test1SOSL.....'+records.size());

 

Opportunity opp = [select id from Opportunity where name = 'Levis' limit 1];System.debug('##### Opportunity ID is.....'+opp.id);

 

}catch (Exception ex) {

System.debug(ex);

}

 

I am able to execute the SOQL query but when executing the SOSL query I get the size of the List as 0.

 

please tell me why it is happening with SOSL and help me go forward

 

 

regards

Sunil

 

 

micwamicwa

Is this code in a testmethod?

 

If yes:

To ensure that test methods always behave in a predictable way, any Salesforce Object Search Language (SOSL) query that

is added to an Apex test method returns an empty set of search results when the test method executes. If you do not want the

query to return an empty list of results, you can use the Test.setFixedSearchResults system method to define a list of

record IDs that are returned by the search. All SOSL queries that take place later in the test method return the list of record

IDs that were specified by the Test.setFixedSearchResults method.