[SalesForce] Get all Community urls in Apex

The title is pretty much self explanatory, but I wanted to know if there is a way by which I can access all Community urls provided I have proper permissions set.

I already looked at Network class but it is only for logged in user and one community.

SO suppose if I have 4 communities created –

  1. www.comm1.com/comm1
  2. www.comm2.com/comm2
  3. www.comm3.com/comm3
  4. www.comm4.com/comm4

I want to access all these 4 urls in normal apex.

Let me know for a way for same.

Thanks,

Ray

Best Answer

You can soql query as:

SELECT Domain, DomainType FROM Domain

SELECT Name, UrlPathPrefix FROM Network

You will get the domain and then all communities and build your logic.