2

I have a Visualforce page that is displayed in two different CustomTabs. In one of the tabs, I would like to have the page's showHeader property to be true, and in the other tab it should be false.

Tab with header:

<?xml version="1.0" encoding="UTF-8"?>
<CustomTab xmlns="http://soap.sforce.com/2006/04/metadata">
    <label>Tab With Header</label>
    <mobileReady>true</mobileReady>
    <motif>Custom33: Desk</motif>
    <page>MyPage</page>
</CustomTab>

Tab without header:

<?xml version="1.0" encoding="UTF-8"?>
<CustomTab xmlns="http://soap.sforce.com/2006/04/metadata">
    <label>Tab Without Header</label>
    <mobileReady>true</mobileReady>
    <motif>Custom33: Desk</motif>
    <page>MyPage</page>
</CustomTab>

Apex page:

<apex:page showHeader="{!showHeader}" sidebar="{!showSidebar}" controller="MyController" action="{!initPage}">
    <!-- stuff -->
</apex>

Controller:

public class MyController {
    public boolean showHeader {
        get {
            // what can I use here?
        }
    }

    public boolean showSidebar {
        get {
            // what can I use here?
        }
    }

    // other stuff
}

As far as I can tell, I cannot pass any data from the tab to the page. Is it possible for the page to know where it is being viewed from so I can set the header and sidebar visibility appropriately?

As an end-route, I could use two separate Visualforce pages with different properties, but I'd rather not go that route if I don't have to.

  • URL params are available – cropredy Dec 29 '16 at 17:05
  • AFAIK, we cannot specify URL params for the VF page in a CustomTab. – asgallant Dec 29 '16 at 17:07
  • hmm, how about two pages each using a common apex:include ? – cropredy Dec 29 '16 at 17:10
1

When I click on a Visualforce Tab in Salesforce Classic, it gives me a parameter like this:

/apex/MyPage?sfdc.tabName=01r290000000Fjb

Not sure if other modes will exhibit the same behavior, but at least in Classic the below should work.

The 01r prefix appears to correspond to the CustomTabDefinition object, which you cannot query for as far as I can tell. I would use a List Custom Setting to store the Id, which will allow you to avoid hard-coding Ids into your markup or code. There are a few different directions you can go from there.


The simplest approach would be to just hold a whitelist of which tabs for which you should hide the header and sidebar. Just store the Id in the standard Name field that comes with the setting. You could have this one custom setting control both properties, or create a separate setting if you want to stick with simple whitelisting. That way, you can use its keyset:

public String tabId
{
    get
    {
        return ApexPages.currentPage().getParameters().get('sfdc.tabName');
    }
}
public Boolean showHeader
{
    get
    {
        return !TabsToHideHeader__c.getAll().keySet().contains(tabId);
    }
}
public Boolean showHeader
{
    get
    {
        return !TabsToHideSidebar__c.getAll().keySet().contains(tabId);
    }
}

A more flexible/scalable solution would be to instead make the custom setting configure several aspects of the tab (checkbox fields here), then assume you should show both when there is no setting. This approach would allow you to specify more aspects of the tab behavior, even just among attributes on your <apex:page> tag.

public TabConfig__c config
{
    get
    {
        String tabId = ApexPages.currentPage().getParameters().get('sfdc.tabName');
        return TabConfig__c.getInstance(tabId);
    }
}
public Boolean showHeader
{
    get
    {
        return (config == null) ? true : config.ShowHeader__c;
    }
}
public Boolean showSidebar
{
    get
    {
        return (config == null) ? true : config.Sidebar__c;
    }
}
|improve this answer|||||
  • This is going into a managed package, so I won't know what the tab object Ids will be once it is installed in a customer's org. Is there a way to get the tab API name from the Id in APEX? I gather that you can do so through the Metadata API, and thus in APEX through 3rd party tools like FinancialForce's apex-mdapi, but I am prohibited from introducing 3rd party dependencies, so those won't work for me. – asgallant Dec 30 '16 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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