function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Workaround ideas for ""Nesting of semi Joins subselects is not supported"?

I have the following working query which fetches back case comment activities for a set of accounts:


select AccountId from Case where Id in (select ParentId from CaseComment where ......) and AccountId in :accountMap.keyset()


except that I end up with duplicate AccountIds which means that it is unnecessarily eating up the governing limits for # of queried rows.  While functionally, I can use a group by statement to get the distinct accountIds, group bys do not affect the queried rows limit for it is simply a filter over the queried rows.


If this is sql, I could have used something like the following but nesting is not supported as noted in documentation: select Id from Account where Id in (select AccountId from Case where Id in (select ParentId from CaseComment  where ....)) and Id in :accountMap.keyset().


Can anyone think of a governing-limit-efficient workaround that will give the right distinct account ids?




Best Answer chosen by Admin (Salesforce Developers) 

Not sure what the rest of your filter looks like on CaseComment but you may be able to use a trigger on casecomment to set a field value on case establish a filtering mechanism at the case level.


I don't think there are any ways to make this more efficient from within SOQL purely itself. I've created an idea for you, vote for it if you would use it were we to deliver it: