+ Start a Discussion
apexdevSunilapexdevSunil 

How to search for an Opportunity using SOSL

Hi

 

I have created an Opportunity whose name is 'myOpp' in my Developer Edition.

I am writing an SOSL query to search for an Opportunity 'myOpp' in the following way.

 

String searchquery='FIND \'myOpp\' IN ALL FIELDS RETURNING Opportunity(id,name,Amount WHERE name = \'myOpp\')';


List<List<SObject>> results = search.query(searchquery);


for(Integer j = 0;j<results.size();j++){ 
Opportunity[] opplist = (List<Opportunity>)results[j];
System.debug('@@@@@ Opp size is .....'+opplist.size());
}  

Even though I have the opportunity for which I make a search when I print the size of opplist I get 0.

 

Please correct my code and suggest me where I am wrong.

 

any help on this is greatly appreciated

 

 

sunil

wesnoltewesnolte

Hey

 

Try without the where clause first just to see what you get. Try this

 

String searchquery='FIND \'myOpp\' IN ALL FIELDS RETURNING Opportunity(id,name,Amount);

List<List<SObject>> results = search.query(searchquery); 

 

List<Opportunity> opps =  (List<Opportunity>)results[0]);

 

Cheers,

Wes 

apexdevSunilapexdevSunil

I have removed the where clause from the query

still I did not get.

 

For executing SOSL querys do I require any permissions.please let me know where I am wrong and correct me.

wesnoltewesnolte

Hey

 

It may be a permission issues but first I'd try selecting the record using SOQL. Just try a straight select and see if anything is returned.

 

Cheers,

Wes

apexdevSunilapexdevSunil

Iam able to execute the SOQL query,but I am not able to execute the SOSL query.

 

should I give permissions any where in the salesforce UI to execute SOSL queries.

 

Please let me know ASAP.