+ Start a Discussion

URLFOR syntax

Hi guys I've browsed around the forums a little and looked through the pdf's but just can't seem to get this one right. I'm missing something simple. I know I've overlooked something but I can't find it. Sorry

Can someone let me know how I can make this bit of code on my visual force page... return to the page I'm currently on once it's clicked?

URLFOR($Action.Sales_Contact__c.Delete, c.Id, null, true)

Basically how do I set RetURL for a URLFOR? If someone could write it out for me that would be great.

I need it to return to /apex/addsalesprospectId={!Account.Id}   when I'm finished.

Sorry and thanks to anyone that helps.

Message Edited by patske on 06-04-2008 11:14 PM
Ron HessRon Hess
This one is documented in the online help, open the app, click help, search for URLFOR
then look on that page for retURL

hope this helps.


Description: Returns a relative URL for an action, s-control, or a file in a static resource archive in a Visualforce page.
Use: {!URLFOR(target, id, [inputs], [no override])} and replace target with the URL or action, s-control, or static resource merge variable, id with a reference to the record, and inputs with any optional parameters. The no override argument is also optional and defaults to "false." It applies to targets for standard Salesforce pages such as $Action.Account.New. Replace no override with "true" when you want to display a standard Salesforce page regardless of whether you have defined an override for it elsewhere.
S-Control Example:
<script src="/soap/ajax/13.0/connection.js">
function init()
var queryResult = sforce.connection.query("Select count() from CaseSolution Where CaseId = '{!Case.Id}'");
var size = queryResult.size;
if (size > 0) {
//go to the standard case close page without invoking the override
window.parent.location.href = "{!URLFOR($Action.Case.CloseCase, Case.Id, [retURL=URLFOR($Action.Case.View, Case.Id)], true)}"
alert("Case must contain at least one solution before it can be closed.");
//go to the standard case detail page
this.parent.location.href = "{!URLFOR($Action.Case.View, Case.Id)}";
<body onload="init()">

In this example, the s-control displays a message to users when they click Close Case on a case with no associated solutions. If the case is associated with at least one solution, the close case page displays as usual. To implement this example, create an s-control with the content above. Then, override the close case option using the s-control.

This example shows how you can validate data using a standard button override. Use validation rules to validate data on a record and an s-control like the one in this example to validate associated data. This example does not apply to records updated using the API.

This example uses the URLFOR function to build Salesforce URLs rather than hard-coding them, which is more scalable. It also sets the no override argument to "true," telling Salesforce to ignore the override and call a standard close case action within an override.

Sorry to be a pain thanks for the help Ron
I don't find the answer/documentation very helpful as its an s-control example and we are in a visualforce forum.
What is the correct syntax for the inputs?
What I am trying to do is create a new opportunity and pass in the AccountID like this:
<apex:commandButton action="{!URLFOR($Action.Opportunity.New, null, [AccountID=ID] ,true)}" value="New Opportunity" id="theButton"/>

I am using an extended Account controller. 
You got it resolved ? I'm looking to pass in some cutsom values to another Page in URL but could not do so ... ?

GerhardNewman2 wrote:
I don't find the answer/documentation very helpful as its an s-control example and we are in a visualforce forum.
What is the correct syntax for the inputs?
What I am trying to do is create a new opportunity and pass in the AccountID like this:

I am using an extended Account controller. 

<apex:commandButton action="{!URLFOR($Action.Opportunity.New, ID, [retURL=myRet])}" value="New Opportunity" id="theButton"/>

Not sure if thats going to help you or not.
In general I use a different way not using URLFOR.  For example in my page:
<apex:commandbutton action="{!assignCP}" value="Assign Creative Planner" rendered="{!ShowAssignCreativePlanner}"/>

and in my controller:
    public PageReference assignCP() {
        PageReference assignPage = Page.Assign;
        return assignPage;

Hope something here help you!
Yes certainly you did helped :) .. i forgot about put() method .. yes that will do. I'll give it a try .. thanks for your help.
Can you reference ApexPages as you would general actions?

Lets say I have an Apex page called 'HelloWorld' that would have the URL: /apex/HelloWord

Can you reference this in URLFOR by doing *something* like:
$Page.HelloWorld as you would $Action.Contact.New?

Definitely and is actually what we recommend - if you use the literal /apex/pageName as a string VF is unable to track this dependency for packaging or metadata integrity enforcement (part of the platform that keeps someone from deleting an in use page or component) etc
So this all makes sense and in a VisualForce page, I can reference the page as I would expect using the following syntax.

In VisualForce

<apex:outputLink value="{!URLFOR($Page.HelloWorld)}">Hello World</apex:outputLink>

 However, I cannot use that syntax in a custom S-Control.  The following S-control does not validate:

In S-Control:


Some background on my use case:
  1. I'm trying to override the Activity History's View All button
  2. I want to add custom logic to the button such that if the current page is displaying the details for a Contact, the link navigates to a different page that if the Current Page is displaying the details for an Account.
  3. I realize that ActivityHistory and Activities are a special beast with various Polymorphic References depending on if the activity is a Task or Event.  However, I recognize that SF has solved this problem in : ui/core/ViewAllActivityHistoryPage which I assume is a VisualForce page that displays the Activity history for an abritrary Object.
ui/core/ViewAllActivityHistoryPage is not a visualforce page - it is implemented using our old presentation framework that has never been made available for public use. The ability to override Activity standard actions with a visualforce page is on the VF roadmap. You are correct that $Page is not available in scontrols (part of our firm stance on not enhancing anything in scontrols which are about to be formally placed into deprectaed status). This interesection of limitations is unfortunate - as a workaround you will need to stick to the /apex/fullyQualfiedPageName. Note that if you are working with a namespaced org it is critical that you prefix the page name with the namespace (e.g. /apex/Dutchdev__mypage would be the fully qualified page name for mypage in an org with the namespace Dutchdev).