I have contact object and Registration Custom Object.

I want to list the registration object fields in contact object using relationship as follows:

SELECT id, name, (SELECT id,name FROM Registrations__r) FROM Contact;

I want to do the same thing using SOSL. is that Possible? I did something like this for Contact fields.

FIND 'searchText' IN ALL FIELDS RETURNING Contact(name,Email);

doesnot know how to use registration object fields here...


This answer is covered by the inestimable wisdom of @sfdcfox here: https://developer.salesforce.com/forums/ForumsMain?id=906F00000008yxvIAA

I quote:

The documentation does not provide an example for this type of query, so I presume that one does not exist (it is not supported). Also, you can't apparently use SOSL as a subquery to SOQL; I couldn't find an example for this syntax either. This leads me to believe that the correct method for doing something like this would be a two-parter that looks like this:

List<account> accountSearch = 
    ((List<Account>)[find 'test' in all fields returning account(id)][0]);

list<account> accounts = 
    [select id,name,(select id,firstname,lastname from contacts) 
        from account where id in :accountSearch];

end quote

In your case, you'll do something like this:

List<Contact> contactSearch = 
    ((List<Contact>)[find 'searchtext' in all fields returning Contact(id)][0]);

list<Contact> contacts = 
    [select id,email,name,(select id,name from registrations__r) 
        from contact where id in :contactSearch];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.