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

How to call URL in Visualforce Page?



I'm overriding New button with Visualforce Page in my existing Object. Condition could be either TRUE or FALSE..If TRUE then I need to call default action where new Object is being called BUT if condition is FALSE then I need to call different VF page.

My question is How to call existing Object Page if condition is TRUE in code..I mean what should be the URL?


This is the URL when I click on New button, How to write this in Apex code?






I think you should be able to achieve this using the action attribute of the apex:page component.


This is an method on your controller that gets called before the page is rendered.  You can then decide whether to allow the user to continue on the current page, or direct them to a different page (including standard pages).


The method returns a PageReference, which you can add URL parameters to.  You may need to do some additional work if you want to pre-fill custom fields on the standard page, as the HTML ids of those fields may be different between sandbox and production etc etc.




Take a look at the URLFor function which can be used to generate the correct URL for an action.   One of its parameters specifies to create the url to get at the standard page instead of the overide page. 


You can invoke URL through PageReference class by using the sample code given below :


PageReference pgref = new PageReference('00l/e?id=' + oppid);

return pgref.


Hope this helps.