I have a search VF page (it is just like google search with text box). In this i am searching all fields of a object then retrieving records by sosl search (upto this functionality it is working fine).

Now i want to search by parent name then i need to retrieve the child records based on parent name. The following is the query i am using:

String searchQuery = 'FIND \'' + searchStr + '\' IN ALL FIELDS RETURNING Account (Id,Name,type),Investor__c(id,name,Account__c,Account__r.name,LastModifiedById,lastmodifieddate,OwnerID,Residual__c);

2 Answers 2


The parent's fields are well, on parent, not on the child ;)

Unless you have some helper text field (preferably indexed/marked as external id) on the child that duplicates the data you'll have to do it in 2 steps. First SOSL for parents and then fire off regular SOQL for children. That second query can be a flat list or maybe you can go with a subquery (just watch out if your related list has > 200 records)


According to the documentation for SOSL the search query has to be within curly brackets, which it seems like yours is not, unless this is added in the actual query. Check the link below to analyze your syntax better. Not much else I can


  • Curly ones are needed only in API calls (REST API, Workbench queries, Real Force Explorer etc.) In Apex you can go System.debug([FIND 'John*' RETURNING User]);. Besides he wrote that the query is working up till certain point...
    – eyescream
    Jul 23, 2014 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .