The current documented way to retrieve the ID of a given community is via the ConnectAPI class.
While this works, the ConnectAPI class has a special requirement: any use of ConnectAPI methods requires
(SeeAllData=True) on related test code.
This flies in the face of best practices when it comes to writing test code, and I'd like to avoid it if possible.
Currently, my code's only use of ConnectAPI is
ConnectApi.Communities.getCommunities(). Is there a SOQL query or some alternative class I can use and avoid the SeeAllData requirement?