Find your content:

Search form

You are here

How can I get a Web Tab's URL from Apex?


Since I cannot remove my legacy Visualforce Tab from my managed package, I would like to redirect the user to a new Web Tab, but I am not sure how to find the URL for my new Web Tab dynamically.

My proposed Visualforce page:

<apex:page controller="My_Controller" action="{!GoToNew}" >

My proposed controller with placeholder:

public with sharing class My_Controller
    public PageReference GoToNew()
        String newPageUrl = FindTabUrl();
        PageReference newPage = new PageReference(newPageUrl);

        return newPage;

    public String FindTabUrl()
         return '';

What is the best way to find the URL in the FindTabUrl method?

Attribution to: Brad Ullery

Possible Suggestion/Solution #1

Although I would not recommend going to all this hassle just to send a user to a web tab (see eyescream's answer), if you really really absolutely had to do this, here's a completely server-side solution:

1) ON Package Installation, either from an Apex Install Handler or a Visualforce "Setup/Getting Started/Configuration" page, do a callout to the Web Services API for your org, performing a describeTabs call. To do this, use WSDL2Apex with the Partner WSDL to generate some Stubs within your package Development org. Also you'll have to include Remote Sites within your package (obviously this is all non-ideal, but hey, it IS a solution... isn't eyescream's answer starting to sound attractive??)

2) Cache the result of this describeTabs callout in a Custom Setting (as per Abhinav Gupta's suggestion), ideally just stripping out the most important information, putting it in a custom Apex class or a Map<String,Object>, and then using JSON.serialize() to convert to a String, and then striping that String across multiple Textarea fields in a Custom Setting (you can have up to 300 textarea fields) following this suggestion. Of course you could go the "easy route" if you don't need this Describe Tabs information ever again, and just store your Web Tab's tab Id in a single text field on your Custom Setting. Forgive me for over-architecting, it's my job :)

3) At run time, in your Visualforce Page's Apex controller, access the stored values in the Custom Setting by reassembling your String, deserializing it into an Object (or just getting the desired Web Tab's Id from a stored field in your Custom Setting if you went the easy route). Because this Tab is not going away from your Managed Package, the tab's Id will remain stable within a given customer's org. So it's fine to store and access it this way.

Attribution to: zachelrath

Possible Suggestion/Solution #2

Their is no direct Sobject or API I believe for the same. So I would suggest storing the web tab ID or URL in a LIST custom setting field (existing on new one).

If you are storing ID only, then using this ID we can use Salesforce URL Apex System class to construct the complete path at run time.

String tabUrl = URL.getSalesforceBaseUrl().toExternalForm() + 'servlet/servlet.Integration?lid=<<TABID from CustomSetting>>&ic=1';

Attribution to: Abhinav Gupta

Possible Suggestion/Solution #3

If you know the Label of your custom tab you can use the following code to redirect to it :

<apex:page >
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
<script src="../../soap/ajax/25.0/connection.js" type="text/javascript"></script>
<script type="text/javascript">     
    window.onload = function() 
        var result = sforce.connection.describeTabs();
        for (var i=0; i<result.length; i++) 
            var tabSet = result[i].get("tabs");
            for(var i=0; i<tabSet.length; i++) 
                var tab = tabSet[i];
                if(tab.label == "yourTabLabel")

I hope it helps!

source : AJAX Toolkit

Attribution to: melmoussaoui

Possible Suggestion/Solution #4

Do you really really need to go to the web tab? Maybe simply replace the body of your old VF tab with sth like this?

<apex:page showHeader="true" sidebar="true">
    <apex:iframe src=""/>

Net result should be similar but 1 redirect less = faster.

Attribution to: eyescream

Possible Suggestion/Solution #5

The describeTabs() solution is an interesting one. describeTabs() is exposed via the SOAP API.

describeTabs() method is a poor name - it should be describeTabset() since it actually returns the tabset or apps that are assigned to the logged in user making the call. The only way you can see all tabs would be to assign all apps in the org to a user (like admin) and make the api call through that user. Web tabs are included; however, we substitute the url attribute with a secure servlet address. For instance, might become

However, that being said, it is a live URL that will redirect the user to the web tab.

You can try this out using the AJAX Debug Shell.

Log into your org and add the following URL at the end of your top level domain: /soap/ajax/26.0/debugshell.html

for instance:

to log in (if you're not already), just type: sforce.connection.login("username","password") to view your tabs, just type: sforce.connection.describeTabs() and drill down on the tabs column to view the tab URLs including your web tabs.

Attribution to: Adam Torman
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content