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
tall jerometall jerome 

Is the Community ID available in Apex?

We have an app that posts to Chatter when it performs a certain function and we're porting this to work in Communities. The one thing we're stuck on is how to set the FeedItem.NetworkScope for the Community from which the FeedItem is being posted. 

Is there a way to obtain the Community ID in Apex so that we can set it as the NetworkScope?
Fabrice TalbotFabrice Talbot
Check this thread to get the network object: https://success.salesforce.com/ideaView?id=08730000000kvysAAA&fromEmail=1
tall jerometall jerome
Fabrice, that looks like a feature request to be able to do what we're attempting, not an actual solution. Or am I wrong?
Fabrice TalbotFabrice Talbot
We have many ISVs doing this through API. The thread I linked to shows how to get the network object. The feature request discussed there is around exposing the site URL in the SOAP API for Network. 

I'd suggest you post your code so a developer can help you.
alouie_sfdcalouie_sfdc
You can use this Apex method for getting the community ID: Network.getNetworkId()

Documentation:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_Network_getNetworkId.htm
tall jerometall jerome
Fantastic! Thanks, guys!
Scott BubScott Bub
This might be a silly question, but is anyone else having an issue opening up the link. I can't get to that documentation. Can you provide a click path to it or another link?
alouie_sfdcalouie_sfdc
It's not working for me either, not sure why. But try this other link:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_network.htm#apex_classes_network
Scott BubScott Bub
That one worked for me, thanks!