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
cpetersoncpeterson 

Getting a pagereference for a standard controller (i.e. a tab)

I've spent a good amount of time looking around trying to find whatever piece of semi-magical syntax I need to be able to get a PageReference to a tab of a standard controller.

 

On the forums I've found the reccomendation to just link to it's URL directly: https://salesforce_instance/001/o.

While that's the quick and easy way, it doesn't work with packages or code deployments, which the code I'm patching will someday be involved with.

 

So in short, I need a portable way of finding a pagereference to a standard controller, say the normal accounts tab. Anybody know an easy way?

Best Answer chosen by Admin (Salesforce Developers) 
wesnoltewesnolte

Hey

 

URLFOR would make the action method work without a need to make controller method calls. Simply put that exact code into the action="" and you're a-for-away.

 

Wes

All Answers

wesnoltewesnolte

Hey

 

Do you need a pageReference or would this be fine:

 

{!URLFOR($Action.Account.Tab,$ObjectType.Account)}  

 

Wes 

cpetersoncpeterson

It's for a controller action method, so a pageref is the only non-ugly way I can see to do it.

I guess I could put a hack in the visualforce pages with that controller to pass {!URLFOR($Action.Account.Tab,$ObjectType.Account)}  to the controller and then generate a pageref from the string, but that's a really ugly hack.

wesnoltewesnolte

Hey

 

URLFOR would make the action method work without a need to make controller method calls. Simply put that exact code into the action="" and you're a-for-away.

 

Wes

This was selected as the best answer
cpetersoncpeterson

ha! I didn't realize you could do that.

It still seems like a rather large oversight to not let you get that info via a pageref, but that trick does what I need in this instance.

 

Thanks Wes! 

 

For anybody who also has this question (and I found a few unanswered before posting this), here's the code to make a cancel button that will return you to the accounts tab. Immediate = true is needed to bypass field validation, which you don't want on a cancel button.

 

 

<apex:commandButton value="Cancel" immediate="true" action="{!URLFOR($Action.Account.Tab,$ObjectType.Account)}"/>