Querying Communities?

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x