[SalesForce] Get Communities Selected Tabs

Using Salesforce Communities I am trying to build a custom UI that utilises some of the standard functionality, like getting the selected tabs from "Manage Communities -> Tabs". According to the documentation I have noticed that this information is exposed via the Metadata API (Network).

There is an APEX Network class too which only has 1 "Documented" method – getNetworkId(). However, when I looked into the controllers of the community site, I found another 2 methods that are not documented anywhere:

forwardToAuthPage(String, String) and communitiesLanding()

Are there any other supported and NOT documented methods of the Network class that I can use to retrieve the selected tabs from a particular community?

UPDATE:

I could not see Network object in the force.com explorer, but I was able to query through SOQL in the Developers Console. Using the Schema Global Describe for the object, I got all the fields, but none of them seems like to be referencing the community selected tabs, even though tabs is documented as a Field in the metadata API documentation.

Best Answer

Update: Spring'14 Release Announcement

DescribeAppMenu() If you’re accessing the API using a custom community URL, the describeAppMenu() call retrieves the tab set associated with the community.

Nice!

Pre: Spring'14 Answer...

Ok I've done a bit of research here...

  • The Network Apex class is now documented in the Winter'14 Apex Developers guide here. Sadly it does not have the getTabs method one would hope to find. Though there is communitiesLanding 'Returns a Page Reference to the default landing page for the community. This is the first tab of the community.'
  • Objects. I've also reviewed the full set of Objects and while we have Network, NetworkMember and NetworkMemberGroup. Again tab info is missing.
  • Winter'14 Apex Describe. I also took a look at the new Winter'14 Apex Describe feature for Tabs, however this is for regular tab sets not Network ones, sigh...

So this leaves the Metadata API...

Something I happen to know a few tricks about when it comes to calling it from Apex. This is an async API so not easy to call from Apex, but not impossible. The main issue I can see though is the permissions of the users of your Network. Salesforce Metadata API requires Setup and Modify All Data permissions. So I assume this would be a stopper for you in calling the API directly from your page as the users would not have the required permissions anyway?

If so, a couple of thoughts occur...

  • Develop an Apex Schedule (every hour?) that calls the Metadata API retrieves the Network tab set and outputs it to a Custom Object you can use on your custom page. There would obviously a lag in the Network admin updating things in the Salesforce UI and the information in the Custom 'Network Tabs' Object being updated. Though to address this you could have a 'Run Now' button to force the information to be updated.

  • Alternative Network Tabs UI. The other option might be to develop your own UI instead the Network Tabs UI, that uses the Metadata API to update the Network Tabs and also your Custom 'Network Tabs' object at the same time, thus keeping the two in sync in real time.

Finally another challenge occurs to me as I write this, the Metadata API is giving a list of tabs irrespective of Object security. So you would need to sub-filter the list by the current user. This might infact be possible by using the aformentioned Winter'14 Apex Describe Tab functionality to filter out tabs that don't exist in both tab sets.

Have a think about the above and give me your feedback, my gut feel is this is one of those battles its better to walk away from and deploy the troops to other areas! That said if you want to fight, I'll join you in the battle! :-)

Related Topic