You need to sign in to do that
Don't have an account?
SOSL finding, but not returning rows for custom objects
Hi all,
I have a strange issue with SOSL where when I query SFDC standard objects like contacts I get back my results as expected, e.g.:
//An anonymous block
List<List<SObject>> searchList = [FIND '*vic*' IN ALL FIELDS RETURNING Contact(id)];
contact[] contacts = ((List<contact>)searchlist[0]);
System.debug('Contacts: '+Contacts);
//Results
Anonymous execution was successful.
20090924185445.738:AnonymousBlock.itil: line 1, column 34: SOSL query with resulting 2 rows finished in 17 ms
20090924185445.738:AnonymousBlock.itil: line 3, column 1: Contacts: (Contact:{Id=0038000000iEdvtAAC}, Contact:{Id=0038000000dx3GGAAY})
But when I try the same thing on a custom object I can see it finding rows, but it doesn't actually return them:
//Anonymous block
List<List<SObject>> searchList = [FIND '*vic*' IN ALL FIELDS RETURNING Incident__c(id)];
Incident__c[] incidents = ((List<Incident__c>)searchlist[0]);
System.debug('Incidents: '+incidents);
//results
Anonymous execution was successful.
20090924185616.733:AnonymousBlock.itil: line 1, column 34: SOSL query with resulting 11 rows finished in 23 ms20090924185616.733:AnonymousBlock.itil: line 3, column 1: Incidents: ()
The SOSL query resulted in 11 rows, but the array is empty. It seems to be finding the records, but not return any data on them.
I can get the records in a simple case like this via a SOQL query, so I know they're in the database and readable from the anonymous block.
Help!
Well I found the issue, and it actually seems to be a bug related to namespaces.
When run without namespace prefixes SOSL says it found rows, but doesn't return them. When run with the namespace explicitly set it then properly returns those rows.
//anonymous block
List<List<SObject>> searchList = [FIND '*vic*' IN ALL FIELDS RETURNING namespace__Incident__c(id)];
Incident__c[] incidents = ((List<Incident__c>)searchlist[0]);
System.debug('Incidents: '+incidents);
//results
Anonymous execution was successful.20091005172625.065:AnonymousBlock.itil: line 1, column 34: SOSL query with resulting 11 rows finished in 28 ms20091005172625.065:AnonymousBlock.itil: line 5, column 1: Incidents: (namespace__Incident__c:{Id=a0H80000001jvycEAA}, namespace__Incident__c:{Id=a0H80000001jjTREAY}, ...)
All Answers
Nobody has SOSL working from Apex with custom objects?!
Is this a security setting somewhere? a bug? I can't find any documentation on what I could be doing wrong.
Well I found the issue, and it actually seems to be a bug related to namespaces.
When run without namespace prefixes SOSL says it found rows, but doesn't return them. When run with the namespace explicitly set it then properly returns those rows.
//anonymous block
List<List<SObject>> searchList = [FIND '*vic*' IN ALL FIELDS RETURNING namespace__Incident__c(id)];
Incident__c[] incidents = ((List<Incident__c>)searchlist[0]);
System.debug('Incidents: '+incidents);
//results
Anonymous execution was successful.20091005172625.065:AnonymousBlock.itil: line 1, column 34: SOSL query with resulting 11 rows finished in 28 ms20091005172625.065:AnonymousBlock.itil: line 5, column 1: Incidents: (namespace__Incident__c:{Id=a0H80000001jvycEAA}, namespace__Incident__c:{Id=a0H80000001jjTREAY}, ...)
I don't think it's a bug. To run SOSL on custom setting you need to enable SOSL setting. To enable SOSL setting on custom setting use below steps (In Lightning Experience):
1. Goto Setup.
2. Search for "Schema Settings" and click.
3. Enable "Enable SOSL on custom settings".
Now run your script:
List<List<SObject>> searchList = [FIND '*vic*' IN ALL FIELDS RETURNING namespace__Incident__c(id)];
system.debug('SOSL Result: '+searchList[0]);
I hope it will work. Good Luck.
Regards,
Tarun