How (programatically) can I get a list of the Communities in an org to present to a System Administrator?

I've setup a community in my development org and published, and I can switch between the Internal org and the Support community using the dropdown int the top right. So far, so good.

However even though I can access and edit that community, I can't seem to find a way to get to it via code.

Running the query select id, name from community simply returns one community, the default Internal one.

Am I missing something obvious or is this just a non-starter?

  • 3
    ConnectApi.Communities.getCommunities() This yielded me the proper results with API version 29. Dec 18, 2013 at 6:30
  • Gah! The version of MavensMate I'm using is calling using v28. Works fine in the dev console! Can you post that as the answer mate?
    – Matt Lacey
    Dec 18, 2013 at 6:36
  • Posted that as an answer :) Dec 18, 2013 at 7:40

1 Answer 1


ConnectApi.Communities.getCommunities() This works from developer console as well as from apex class, but you must use API 28.0 (or above).

11:56:52:193 USER_DEBUG [5]|DEBUG|ConnectApi.CommunityPage[buildVersion=28.0, communities=(ConnectApi.Community[buildVersion=28.0, description=funn2comunity, id=0DB90000000PBSLGA4, invitationsEnabled=false, name=Fun2community, sendWelcomeEmail=true, status=Live, url=/services/data/v28.0/connect/communities/0DB90000000PBSLGA4, urlPathPrefix=null], ConnectApi.Community[buildVersion=28.0, description=This is a funcommunity, id=0DB90000000PBQtGAO, invitationsEnabled=false, name=Funcommunity, sendWelcomeEmail=true, status=Live, url=/services/data/v28.0/connect/communities/0DB90000000PBQtGAO, urlPathPrefix=mainportal]), total=2]

Communities is called Network in the SObject API. So if you didn't want to use the ConnectApi, you could query Communities by running:

SELECT id, name FROM Network
  • @LaceySnr It worked with API 28.0.I think the bug is with mavens mate plugin . Dec 18, 2013 at 7:42
  • Hmm, I'll investigate more. There's no reason for the code to behave differently when being run from different places, could be I was on an even older API version...
    – Matt Lacey
    Dec 18, 2013 at 7:55
  • [1]|DEBUG|ConnectApi.CommunityPage[buildVersion=28.0, communities=(), total=0] your logs shows you were in version 28.0 .Anyways i will dig in as well Dec 18, 2013 at 8:12
  • Hang about, I was being an idiot. When I ran the code from MM it was executing in a different org ;) Bet you need API 28+!
    – Matt Lacey
    Dec 18, 2013 at 9:21
  • Was able to run it with 26th version as well.:) Dec 18, 2013 at 9:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .