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
AlexPHPAlexPHP 

Using variables in the INPUTS parameter of URLFOR

Is it possible to use variables in the key of an INPUTS parameter of URLFOR?

 

For example, using a Custom Settings variable:

<apex:commandButton action="{!URLFOR($Action.MyObject__c.New, null, [$Setup.CustomSettingName__c.CustomFieldName__c=controllerClass.Id])}" value="My Button" title="Button Title"/>

 

As you can see, the action for the commandButton is the URLFOR the New functionality of MyObject__c.

 

I am trying to pass in an input parameter where the parameter key is a  Custom Settings invocation, and the value is my controller class's Id variable.

 

When I try to do this, the the Custom Settings variable is not evaluated, instead the button treats it as a string literal and directs me to:

 

 

 

%24Setup.CustomSettingName__c.CustomFieldName__c=a0MT0000002NnCnABC

It just encoded the '$' sign and didn't evaluate the variable.

 

How can I use a variable as the key in the inputs parameter for the URLFOR function?

 

Much thanks

Message Edited by AlexPHP on 03-09-2010 06:49 PM
Eric@AppirioEric@Appirio

Did you get an answer?  One way you can do this is to take the input parameter out of the URLFOR() and add it to your string.

 

 

action="{!URLFOR($Action.MyObject__c.New)}&{!$Setup.CustomSettingName__c.CustomFieldName__c}={!controllerClass.Id}" 

 

 

NaishadhNaishadh

why you use urlfor when you have option of binding any pagereference method with action. Try this

 

 

<apex:commandButton action="{!URLFOR($Action.MyObject__c.New, null, [$Setup.CustomSettingName__c.CustomFieldName__c=controllerClass.Id])}" value="My Button" title="Button Title"/>

-----------------

<apex:commandButton action="{!redirect}" value="My Button" title="Button Title"/>

public PageReference redirect() {
    //suppose your myobject id starts with a0X/
    PageReference newPage = new PageReference('/a0X/e');
    newPage.getParameters().put('<customFieldName>','<fieldvalue');
    
    newPage.setRedirect(true);

    return newPage;
}