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
abhi_developerabhi_developer 

how to return custom objects home page on command button click

hi all,
 
i am trying to return custom_objects home page when i click on command button.
 
i have written this code but its not working.
 
<apex:commandButton value="gototab" action="{!$Action.custom_object__c.Tab}"/>
 
please suggest me a way of doing this in visualforce with command button only.
 
 
-Abhishek singh
abhi_developerabhi_developer
hi all,
 
though i am able to return the partial url of my custom objects home tab but am not getting how to pass it to "action" of command button.
 
here is the code for getting partial url
 
"{!URLFOR($Action.customobject__c.Tab, $ObjectType.customobject__c)}"
 
it returns the partial url of custom object's tab home page(like:- /a07/o)
 
but when i pass this url to action of custom button like
 
<apex:commandButton value="returnHome" action= "{!URLFOR($Action.customobject__c.Tab, $ObjectType.customobject__c)}"/>
 
 it gives error.
 
please help me with it.
 
thanks in anticipation :)
 
-Abhishek singh
 
 
 
Ron HessRon Hess
actions in Visualforce are performed on the controller for that page, you will have to write a controller, in that controller, you can cause the page to navigate to most any other page in the app. See navigation in the Visualforce documentation
abhi_developerabhi_developer
Hi Ross,
 
Thanks, that's true but am not getting how to get "Tab home" page's reference.
 
Is there any easy way of getting Tab Home page's reference in Apex.
 
If you know please help me.
 
Thanks in anticipation.
 
-Abhishek Singh
abhi_developerabhi_developer
Hey i made it.. got d way..!!
dchasmandchasman
<apex:commandButton> is meant to be used to invoke controller actions so it is not the right way to attack this (there will be a specific error message indicating that you tried to specify an invalid action as the value for the action attribute in a future release) but writing a controller for this simple nav to a page case would be overkill (and be more expensive than needed). We're currently missing the component you're looking for - e.g. something along the lines of <apex:outputButton> but remember that you can use any standard HTML/CSS/Javascript in your visualforce pages so the following would be viable options:

<input type="button" class="btn" value="Go Home" onclick="window.location = '{!URLFOR($Action.customobject__c.Tab, $ObjectType.customobject__c)}'" />

if you must have a button (although buttons are typically best reserved to convey some type of mutating operation like a Save or Edit) or

<apex:outputLink value="{!urlFor($Action.customobject__c.Tab, $ObjectType.customobject__c)}">Go Home</apex:outputLink>

if you decide to use a link instead...