8

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.

3

3 Answers 3

6
+200

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! :-)

2
  • Ah that's great effort, appreciate it! You're right about the security and the sub-filter, I will need to handle that too. Scheduled job it is, according to the current functionality and documentation. Let's hope someone from SF reviews this and amends the documentation to make it more clear. I will definitely spread a word around in regards to this issue. Commented Sep 11, 2013 at 10:20
  • Your most welcome, its so close with some of the more 'native' options as well. The Metadata API is not the most friendly either when it comes to reading as it gives a zip file back, my thinking is to read it via an approach i outline in my blog. However I would class this as highly experimental, so as I said if you have other wars to wage you may want to save this for a rainy day (as we say in the UK!). :-) andyinthecloud.com/2012/11/04/… Commented Sep 12, 2013 at 9:19
2

Ok now here's a really dirty one, I feel almost ashamed to suggest it but you could try to screen scrape the information. Use either Apex HTTPRequest from a controller or client-side jquery to call the standard community home page in the background. Traverse the returned HTML DOM looking for an unordered list (ul) with id "tabBar" and retrieve the ids of the child list (li) elements. jQuery would probably make it easier to get the element ids. However you should be able to get the selected tabs this way but of course it should be a makeshift solution until the selected tabs are available directly.

1
  • All makes sense and it's kinda thing that I thought about too, as well as Keith's answer. My question was specifically for server-side which is more reliable and the not complete documentation gives the impression that it's logically possible... Thanks for your effort though! Commented Sep 11, 2013 at 10:24
0

Not really what your asking for but to do what you're describing i've often found its easier to just load the standard header (and tabs) on the page and then just hide/show and style things via css.

That way you get the flexibility of being able to manage tabs in the GUI app but dont have use standard salesforce style

its a little hacky but it does work

1
  • That was my initial thought but as I want to build a complete custom GUI based on the selected tabs, there will be lots of CSS hacking if I use the standard layout. Commented Sep 1, 2013 at 23:21

You must log in to answer this question.

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