Using a SOSL query with a SubSOQL query
|Knowledge Article Number||000187803|
|Description||In SOSL if you are using SOQL to fetch the records to be compared by 'IN' Or 'NOT IN' operator, the SOSL throws an exception :- System.QueryException: unexpected token: 'common.api.soap.parse.SoapParseNode' :
Example query throwing exception :-
FIND 'Test' IN NAME FIELDS RETURNING Campaign ( Id WHERE Id IN ( SELECT CampaignId FROM CampaignMember WHERE ContactId = '003J000000mmEZp' ) LIMIT 2000)
|Resolution||The Exception is being thrown by SOSL as it does not support SOQL as a subquery.
Also the records which are being compared by 'NOT IN' or 'IN' should be surrounded by single quotes.
Example :- Firstly, the SOQL which is being used as a sub query in SOSL should be used separately.
SELECT CampaignId FROM CampaignMember WHERE ContactId = '003J000000mmEZp'
Secondly, use the records as a string and each record surrounded by single quotes.
For Example :-
FIND 'Test' IN NAME FIELDS RETURNING Campaign (Id WHERE Id IN ('701J00000006dJNIAY', '701J00000006dJNIAY','701J00000006tzhIAA','701J00000006c5kIAA','701J00000006c5QIAQ') LIMIT 2000)
NOTE :- The IDEA to support SOQL as the inner part of SOSL is as follows: