Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have one VF page that I'd like to use for multiple tabs depending on some logic in the controller. Is there any way to set tabStyle dynamically? I've tried both of the following, and neither one works:

Attempt #1

<apex:page ... tabStyle="{!IF(some_logic_is_true,'TabA__tab','TabB__tab')}" ... >

Attempt #2

/* in the controller */
public String getTabStyle () {
    if (some_logic_is_true) {
        return 'TabA__tab';
    return 'TabB__tab';


<!-- the VF Page -->
<apex:page ... tabStyle="{!tabStyle}" ... >

Result: Both of these approaches resulted in the following error:

Save error: Invalid tabStyle '{!tabStyle}' specified.  If you are trying to reference
a custom Visualforce tab, you must append '__tab'.

Any other ideas out there?

share|improve this question
up vote 5 down vote accepted

There is no way to set the tabstyle dynamically. You can vote for the idea here.

You will have to create a separate (empty) visualforce page for each of the tabs that you want to be selected and either include your real page:

<apex:page id="thePage" tabstyle="TabA__tab">
    <apex:include pageName="realpage"/>

Or turn your page into a visualforce component and include it that way.

share|improve this answer

I can't find a way of how to customize 'tabStyle' in Page, but you can try to use 'tabStyle' in the apex:pageBlock, see,

VF page,

<apex:page controller="page_tabStyle" showHeader="true" sidebar="false"  >
  <apex:pageBlock title="Hello {!$User.FirstName}!" tabStyle="{!IF($CurrentPage.Parameters.render == 'Account', 'Account', 'Contact')}"  >
        This is your new page for the {!name} controller. <br/>
        You are viewing the {!} account.

Controller, `public class page_tabStyle {

public String getName() { return 'MyController'; } public Account getAccount() { return [select id, name from Account where id = :ApexPages.currentPage().getParameters().get('id')]; }


When you call like,

you got the style of Account,

you got the style of Contact.

share|improve this answer
It seems you can't call Controller method directly in tabStyle, so you have to determine how to communicate on the VF page. – Jia Hu Jan 22 '13 at 2:01
Nice, but per the docs, this only controles "the color scheme of the page block", and the key issue for me is which tab appears to be selected in the tab bar. – Benj Jan 22 '13 at 2:09
I did a variation of this, I used <....tabStyle="{!IF(strObjNm<>null,strObjNm,'Contact')}"> strObjNm is the API Name of the object that I want to use in the controller. So far it's worked great in my controller – Jason Hardy Sep 5 '15 at 0:07

Your Answer


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.