function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Murali0089Murali0089 

Community Id

Hi everyone

 

Please help me how to acheive the community Id in apex   urgent,,,

 

Thanks in advance

 

Regards,

Murali

Sonam_SFDCSonam_SFDC

Hi Murali,

 

You can use the ID field in Community table to get the Community ID: e.g.

idea.CommunityId = community.Id;
__sandra____sandra__
I tried that but I am having the error !

FATAL_ERROR|ConnectApi.ConnectApiException: Illegal value for parameter: 'communityId': 09aU0000000PC1cIAG

How to correctly retreive the community ID?

Thanks
Sonam_SFDCSonam_SFDC

Hi Sandra,

 

You can use SOQL to retrieve the communityID , sample code:

 

Community community = [ SELECT Id FROM Community WHERE Name = 'INTERNAL_COMMUNITY' ];

   question.communityId = community.id;
__sandra____sandra__

Thanks but I have already tried that and it is not working

 

Actually I am trying to implement a custom chatter feed for a community

 

I m using the code of the quick start : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_connectapi_quickstart.htm

 

but in order to display the feed related to the community I created (not the internal community), I shoud pass the community Id to the ConnectApi class

 

but I  keep having the error saying the Id is not valid as a comunityId for the call : ConnectApi.ChatterUsers.getGroups(..)

Sonam_SFDCSonam_SFDC

Know its a slightest possibility but could you confirm that the ID you are passing is within quotes as Id is a string - also could you paste your code here so i have a better idea..

__sandra____sandra__

Here is the code. By the way, after enabling and creating a first community, the table Community contained only one record, which is 'internal community', after enabling Ideas for the community, and specifying a zone, there was a new record created in the Community Table having the name 'Ideas for community'

 

So I wonder if it is really the Community Id or an Idea Zone ID...

 

 

When debugging the code bellow, I keep having the error :

 

05:53:42.943 (943049000)|SYSTEM_METHOD_EXIT|[33]|ConnectApi.ChatterUsers.getGroups(String, String, Integer, Integer)
05:53:42.943 (943187000)|FATAL_ERROR|ConnectApi.ConnectApiException: Illegal value for parameter: 'communityId': 09aU0000000PC1cIAG

(System Code)
Class.GroupFeedController: line 33, column 1

 

global class GroupFeedController{
    
  // Declare and assign values to strings to use as method parameters.
    private static List<Community> customCommunity = [Select Id, Name From Community where name = 'Ideas for community'];
    private static String communityId = customCommunity[0].Id;
    private static String userId = 'me';
    
    // Holds the ID of the selected group.
    // Pass this property to getFeedItemsFromFeed to get the group's feed.
    global String groupId { get; set; }
 
    // Get the IDs and names for all of the groups 
    // the logged-in user is a member of. Add them to
    // a List of SelectionOption objects. This List populates
    // the drop-down menu in the GroupFeed custom component.
    global static List<SelectOption> getGroupOptions() {
        List<SelectOption> options = new List<SelectOption>();
        
        // Adds a blank option to display when the page loads.
        options.add(new SelectOption('', ''));
        
        // Declare and assign values to strings to use as method parameters. 
        Integer page = 0;        
        Integer pageSize = 100;
        
        // Use Chatter in Apex to get the names and IDs of every group
        // the logged-in user is a member of.
        // Chatter in Apex classes are in the ConnectApi namespace.
        // communityId -- a community ID or null.
        // userId -- the user ID or the keyword 'me' to specify the logged-in user.
        // page -- the page number to return.
        // pageSize -- the number of items on the page.
        ConnectApi.UserGroupPage groupPage = ConnectApi.ChatterUsers.getGroups(communityId, userId, page, pageSize);
        
        // The total number of groups the logged-in user is a member of.
        Integer total = groupPage.total;
        
        // Loop through all the groups and add each group's id and name
        // to the list of selection options.
        while (page * pageSize < total) {
            // groupPage.groups is a List of ConnectApi.ChatterGroupSummary objects.
            // ChatterGroupSummary is a subclass of ChatterGroup.
            // For each ChatterGroup object in the List...
            for (ConnectApi.ChatterGroup grp : groupPage.groups) {
                // Add the group's ID and name to the list of selection options.
                options.add(new SelectOption(grp.id, grp.name));
            }
           
            page++;
            
            if (page * pageSize < total) {
                // Get the next page of groups.
                groupPage = ConnectApi.ChatterUsers.getGroups(communityId, userId, page, pageSize);
            }
        }
        
        // Return the list of selection options.
        return options;
    }
    
    // Get the feed items that make up a group's feed.
    global List<ConnectApi.FeedItem> getFeedItems() {
        if (String.isEmpty(groupId)) { return null; }
        // To get the feed for a group, use the Record feed type and pass a group ID.
        // getFeedItemsFromFeed returns a ConnectApi.FeedItemPage class.
        // To get the List of ConnectApi.FeedItem objects,
        // add the .items property to the call.
        return ConnectApi.ChatterFeeds.getFeedItemsFromFeed(communityId, ConnectApi.FeedType.Record, groupId).items;
    }
    
    public PageReference choose() {
        return null;
    }
    
}

 

__sandra____sandra__

I found the correct Community ID...

 

I log debugged the following line

 

 System.debug('#####' + ConnectApi.Communities.getCommunities());

 

So I had the list of communities the running user has access to.

 

The ID looks like '0DBU00000004CBdOAM'

 

It is not mentioned in any Community documentation how to retreive this ID! I looked in all the Salesforce guides!

 

Thanks anyway

Sure@DreamSure@Dream
Hi Sandra,

I am also trying to create custom chatter feed for community. Could you please help me with it?
FlorSFFlorSF
Thanks __sandra__ !
Tye RobinsonTye Robinson
ConnectApi.Communities.getCommunities() Will give you the id you want.
sunil Wagganavarsunil Wagganavar
select id,name from network  This will hep you to get the list of all community's name and IDs
shankar Nadimpalli 3shankar Nadimpalli 3
hi guys 
ConnectApi.Communities.getCommunities() this will give all the communities related data ...what if i have multiple commuties but i need to pick it only particular community that i have logged in ...this should happen dynamic ..and also is there a way to find community name dynamically that will also work for me so that based on that name i will query that ID ....can anyone help on this
shaohua wangshaohua wang
Can get community id in the lwc, and pass it to the apex code

import COMMUNITY_ID from '@salesforce/community/Id';
Arun Kumar 1141Arun Kumar 1141

Hi Murali,

you can use this soql in your Apex code for fetching community Id, hope this will work.

SELECT Id, Name, UrlPathPrefix FROM Network WHERE UrlPathPrefix != null 

Please mark it as the best answer if it will help you.

Thanks