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
navanitachoranavanitachora 

Redirecting to a specific tab in a tabpanel

Hi,

 

I am at present working on a visualforce interface similar to the one shown at:

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_tabs.htm

 

I would like to redirect to a specific tab under the Accounts tab. For example the opportunities tab under the Account tab using the URLFOR function.

 

I could not find any examples that did this which is why I am little puzzled about how to go about this.

 

Thanks in advance.

nav

vishal@forcevishal@force

You can use the selectedTab attribute in <apex:tabPanel>, it determines the tab that is selected. So when you want to redirect to Opportunity Tab, you can simply have the selectedTab set dynamically and assign it the Opportunity Tab Name.

 

See example:

 

<apex:tabPanel switchType="client" selectedTab="{!selectedTab}"  id="AccountTabPanel" tabClass="activeTab"  inactiveTabClass="inactiveTab">  
      <apex:tab label="Details" name="AccDetails" id="tabdetails">
         <apex:detail relatedList="false" title="true"/>
      </apex:tab>
      <apex:tab label="Contacts" name="Contacts" id="tabContact">
         <apex:relatedList subject="{!account}" list="contacts" />
      </apex:tab>

</apex:tabPanel>

 

If you want to launch this from some other link/page, add this parameter - /apex/yourpagename?tab=Opportunities

 

and then in your controller, your constructor should assign the parameter value to 'selectedTab' variable.

selectedTab = ApexPages.currentPage().getParameters().get('tab');

 

I hope this clears your doubt!

navanitachoranavanitachora

Thanks Vishal,

 

But I am afraid I am still having problems. My code for the controller is below:

 

public with sharing class Administration {
    
    public String selectedTab { get; set; }
    
    public Administration() {
    //    selectedTab = 'accounts';
    }
    
    public String getSelectedTab() {
        ApexPages.currentPage().getParameters().get('tab');
        if (selectedTab == null) {
            System.debug('inside if');
            selectedTab = 'accounts';
        }
        else {
             System.debug('inside else');
        }
        
        System.debug('=================' + selectedTab + '================');
        return selectedTab;
    }    
}

 and my visualforce pages looks like this:

<apex:page controller="Administration" showHeader="true" sidebar="false" tabStyle="Administration__tab">
    <apex:tabPanel switchType="server" id="theTabPanel" selectedTab="{!selectedTab}">
        <apex:tab label="Accounts" id="accounts">
            <h2 style="font-size: 150%; margin-left: 5px; margin-top:5px; display: block;">Accounts</h2>
            <apex:enhancedList type="Account" height="600" rowsPerPage="25" id="AccountList" />
        </apex:tab>
        <apex:tab label="Projects" id="projects">
            <h2 style="font-size: 150%; margin-left: 5px; margin-top:5px; display: block;">Projects</h2>
            <apex:enhancedList type="Project__c" height="600" rowsPerPage="25" id="ProjectList" />
        </apex:tab>
        <apex:tab label="Milestones" id="milestones">
            <h2 style="font-size: 150%; margin-left: 5px; margin-top:5px; display: block;">Milestones</h2>
            <apex:enhancedList type="Milestone__c" height="600" rowsPerPage="25" id="MilestoneList" />
        </apex:tab>
        <apex:tab label="Activities" id="actvities">
            <h2 style="font-size: 150%; margin-left: 5px; margin-top:5px; display: block;">Activities</h2>
            <apex:enhancedList type="Activity__c" height="600" rowsPerPage="25" id="ActivityList" />
        </apex:tab>

 I cannot see any of the debug statements show up in my system log.

 

The edit and delete links in the enhanced list are overriden by a visualforce page that has a single script tag like so:

 

<script type="text/javascript">
        window.top.location.replace("{!URLFOR($Action.Project__c.Edit, Project__c.id, [saveURL='/apex/Administration?tab=projects', retURL='/apex/Administration?tab=projects', cancelURL='/apex/Administration?tab=projects'], true)}");
    </script>

 which adds the appropriate tab name in my case my tabs are called accounts, projects, milestones and actvities. When I click the edit link for a particular project it goes to the standard edit page and then redirects back to the Administration tab this bit works. But I would also want it to select the project tab under the tab panel for where the edit link was clicked on.

 

The tab variable is assigned in the URL and I can see it but I think it is not assigned for some reason.

 

Would be most grateful for any pointer you could give me.

 

Thanks in advance.

nav

vishal@forcevishal@force

Hey,

 

I went through your code. In the method getSelectedTab()

 

You are not assigning the usl parameter value to the variable 'selectedTab'. You are only checking if it is null, else you returning the default value (accounts).

 

 

public String getSelectedTab() {
        selectedTab = ApexPages.currentPage().getParameters().get('tab');
        if (selectedTab == null) {
            System.debug('inside if');
            selectedTab = 'accounts';
        }
        else {
             System.debug('inside else');
        }
       
        System.debug('=================' + selectedTab + '================');
        return selectedTab;
    }   

 

You need to assign the url parameter to the variable. Please try making the above change and let me know if that works correctly.

navanitachoranavanitachora

Sorry I had it right in my code just pasted it wrong. According to the logs my getSelectedTab method is not even being entered into.

 

So there is somethng I have done wrong here.

 

Should I put all the code into the constructor and see if that works.

 

Grateful for any pointers you maybe able to give me.

 

Thanks,

nav

navanitachoranavanitachora

Solved the problem instead of setting selectedTab="{!selectedTab}"  setting value="{!selectedTab}" works for me flawlessly. Found the solution at the followinh link:

 

http://force201.wordpress.com/2012/05/31/keeping-track-of-the-selected-tab-of-an-apextabpanel-in-the-controller/

 

Hope this helps someone. :-)

 

Cheers,

nav