Trying to build group hierarchy to display public groups and which public groups they inherit

apexpublic-groupsoql

The issue is that if I use something like

[SELECT Id, GroupId, UserOrGroupId FROM GroupMember WHERE GroupId IN:GroupIds]

The issue is that it returns all group members I don't want such as user/role memberships I have tried using like etc but this

 [SELECT Id, GroupId, UserOrGroupId FROM GroupMember WHERE GroupId IN:GroupIds AND UserOrGroupId IN (SELECT Id FROM Group WHERE Type = 'Regular')]

my main query on here is (SELECT Id FROM Group WHERE Type = 'Regular') doesn't seem to be using query rows in limits and I cannot find any restrictions as to how many records it can compare against? what are the limits of doing it this way or is there a better way?

Best Answer

As far as I'm aware, there's no extra limits placed on subquery filters. You'll still be subjected to the 50k row limit for the records returned, and you will likely be subject to the selective query limits. Further, there's a limit of 30,000 groups to an org, and a user can't be in more than 300 groups, so it should be impossible to exceed any potential limit that might otherwise appear if you were querying an object that has unlimited storage. I would definitely recommend this over a for loop to check each record, as it will be more efficient in governor limits and also more efficient in CPU time and actual wall-clock time.