Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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}" >
</apex:page>

My proposed controller with placeholder:

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

        return newPage;
    }

    public String FindTabUrl()
    {
         return '';
    }
}

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

share|improve this question
add comment

5 Answers

up vote 3 down vote accepted

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="http://www.example.com"/>
</apex:page>

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

share|improve this answer
    
+1 For not going to the web tab --- definitely saves time to skip that step. –  zachelrath Dec 13 '12 at 20:56
    
I like this idea best. My final solution (before I saw this answer) was to redirect the user to the Show All Tabs page with an apex:Page action. –  Brad Ullery Dec 14 '12 at 17:53
add comment

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>
<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")
                    window.parent.location=tab.url;
            }
        }
    }
</script>

I hope it helps!

source : AJAX Toolkit

share|improve this answer
1  
Unfortunately, doing this through javascript on the onload will cause some amount of delay before the screen is refreshed. As opposed to doing your redirect through the VF page action, which happens seamlessly in most cases. –  Jeremy Nottingham Aug 29 '12 at 19:58
2  
Thank for the idea. Unfortunately not all tabs per app are returned by the describeTabs() method. The tabs are only returned if the user has them selected as a default tab. –  Brad Ullery Aug 29 '12 at 20:27
add comment

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';
share|improve this answer
    
I think the Id can be different in each org that has installed the managed package. For new installations you could maybe cheat with some post-deployment scripts, for existing ones - ask Sysadmins to fill in the setting for you? Messy... –  eyescream Oct 25 '12 at 21:31
add comment

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, http://www.google.com might become https://na1.salesforce.com/servlet/servlet.Integration?lid=01r30000001SVQv&ic=1.

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: https://c.na1.visual.force.com/soap/ajax/26.0/debugshell.html

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.

share|improve this answer
add comment

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.

share|improve this answer
    
Wow, that's quite hardcore... Still clunky I'd say, developer/config sandbox will be refreshed with no data in the custom settings so I'd code against that in the access to the tab, not necessarily only in install handler. +1 because it answers the actual question but I'll stick to my answer if I'll ever need something like that ;) –  eyescream Dec 15 '12 at 9:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.