To all the expert SOSL gurus lurking out there, I thought this will be an interesting one:
I have some SObjects of different types and I want to return their Name
values in a single query.
In advance, I know the IDs and the ObjectTypes of the records whose Names I wish to retrieve. It seems 'wrong' to make several SOQL queries even though there aren't too many types.
So being a good platform citizen, I'm using Dynamic SOSL to retrieve what I need in a single query:
List<List<SObject>> sobjectsLists = Search.query(
'FIND {*?*} RETURNING ' +
'CustomOne__c (Name WHERE Id IN (\'a01000000000000AAA\')),' +
'CustomTwo__c (Name WHERE Id IN (\'a02000000000000AAB\')),' +
'CustomThr__c (Name WHERE Id IN (\'a03000000000000AAC\'))'
);
System.debug(sobjectsLists);
But there is one problem: I must specify at least one FIND character and {*?*}
doesn't cut it.
System.SearchException search term must be longer than one character: ?
I've tried this to no avail: {*a* OR *b* OR *c* OR *d* OR *e* OR ...}
but even if that did work, it wouldn't help in the case that some twisted cowboy puts underscore (_
) or god forbid umlaut (ä
).
Any guidance on how I can get the Name
of all these records at once?