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
LukLuk 

SOSL - Find - problem reading results

Hi,

 

I read  SOSL  documentation & examples, although I can't seem to read the results I get from "Find" query.

 

When I run the following code, I can see in the debug that it found 21 results.

 

List<List<SObject>> searchList = [Find 'Ja*' RETURNING candidate__c];

 

 

When I try to read them I get an empty "Candidate__c" list:

 

if(searchList != null){
     Candidate__c []cands = (List<Candidate__c>)searchList[0];

     for(Candidate__c c : cands){
System.debug('Found Id '+c.Id);

     }

}

 

If I try to use SOQL - select, I can see the results. 

 

Should I set special flags in-order to use SOSL?

 

Appreciate any help!

Uri

 

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
LukLuk

Found the solution, it seems that for custom objects (under managed package) I should add namespace before.

So for my example I should simply placed:

 

skills__Candidates__c

 

instead of

 

Candidates__c

 

See this post:

 

http://boards.developerforce.com/t5/Apex-Code-Development/SOSL-finding-but-not-returning-rows-for-custom-objects/m-p/149947#M20972

 

 

Thanks for your help!

Uri

All Answers

Starz26Starz26

This:

 

List<List<sObject>> tl = [Find 'Marion*' IN ALL FIELDS Returning FSA__c];
FSA__c[] fsa = (FSA__c[])tl[0];
system.debug(fsa);

 gave me these results in the debug log....

 

20:01:34:142 USER_DEBUG [3]|DEBUG|(FSA__c:{Id=a0MJ0000000E039MAC})

 

 Yours looks fine, can you post the debug log?

swethasfdcswethasfdc

U can interate the result in for loop and print it.

 

public class Retrievesoslresult
{
    Public static void resultmethod()
    {
    List<List<SObject>> result=[Find 'name*' in all fields returning custom_obj1__c];
    //system.debug('result is:.....'+result);
    /*for(List<SObject> r:result)
    {
        System.debug(r);
    }*/
    
    /*custom_obj1__c[] cus=(custom_obj1__c[])result[0];
    System.debug(cus);
    }*/
    for(custom_obj1__c[] cus:result)
    {
        system.debug('cus....:'+cus+'\n');
    }
}
}

 In all these ways u can retrieve the result.

 

I didn't got of what you said about special flags in-order to use SOSL. can you say it clearly.

LukLuk

When executing the "Find" query the debug logs outputs:

 

15:05:26.118 (118279000)|SYSTEM_METHOD_EXIT|[32]|System.debug(ANY)
15:05:26.118 (118371000)|SOSL_EXECUTE_BEGIN|[35]|Find 'Ja*' RETURNING candidate__c,jobposition__c
15:05:26.130 (130221000)|SOSL_EXECUTE_END|[35]|Rows:21

 

When traversing the results I get empty list:

 

15:05:26.130 (130301000)|USER_DEBUG|[37]|DEBUG|In [searchTags] Selected Tag Records ==> (())
15:05:26.130 (130310000)|SYSTEM_METHOD_EXIT|[37]|System.debug(ANY)
15:05:26.130 (130319000)|SYSTEM_METHOD_ENTRY|[38]|System.debug(ANY)
15:05:26.130 (130332000)|USER_DEBUG|[38]|DEBUG|In [searchTags] Selected Tag Records ==> ()

 

 

Thanks!

Uri

 

 

LukLuk

I just tried running the same "Find" query on Standard Object "Event" and I could read the results successfully.

When I apply a similar "Find" on a custom object "Candidate__c"  from some reason I can not get the results.

 

Maybe it is a configuration issue?

LukLuk

Found the solution, it seems that for custom objects (under managed package) I should add namespace before.

So for my example I should simply placed:

 

skills__Candidates__c

 

instead of

 

Candidates__c

 

See this post:

 

http://boards.developerforce.com/t5/Apex-Code-Development/SOSL-finding-but-not-returning-rows-for-custom-objects/m-p/149947#M20972

 

 

Thanks for your help!

Uri

This was selected as the best answer