3

Is it possible to get the Id(tabName) of a tab by its Name e.g. to avoid hard coded links like this:

<apex:outputLink value="/apex/testPage?sfdc.tabName=01ri0000000QgAK">Test Page</apex:outputLink>
1

1 Answer 1

2

If I'm correct in assuming you're passing in the tab name to your visualforce page to determine which tab is displayed in you actually don't need to do this.

Instead use the apex:page tabstyle attribute to set your tab. For example

<apex:page tabStyle="Account"> <!-- For Standard Object Tab -->
<apex:page tabStyle="MyObj__c"> <!-- For Custom Object Tab -->
<apex:page tabStyle="Custom__Tab"> <!-- For Custom Web/VF Tabs -->

An important caveat is you have to use a literal value for tabStyle. So If you want different tab styles in some cases in others you'll need to create a visualforce page for both. To stay DRY you'll want to use apex:include or a component to encapsulate the core of the page and reference that in the pages for the different tab styles.

Alternatively if you were trying to link to an object based tab you can use the $Action for it. I'm not aware of a simliar approach for custom web or visualforce tabs (although it's really not needed for visualforce since you can set the tab on the page.

<a href="{!URLFOR($Action.Account.Tab)}"/> <!-- Standard Object Tab -->
<a href="{!URLFOR($Action.MyObj__c.Tab)}"/> <!-- Custom Object Tab -->

Unfortunately the ID for the tab is not available to APEX. It available with the Metadata API and ANT. See this answer for a discussion on getting the ids for custom fields for more details.

Bear in mind that the ID will be different for tabs created in sandbox and later migrated to production. However, ids for tabs present in production prior to a sandbox refresh will be the same. Finally, if they ever migrate your org to a different instance all the IDs will change.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .