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

Problem With Page Redirecting Using Param To Pass Parameter

I get a consistant error message when I try and use a commandlink action to assign a value to pass to a new page.  In the controller, the Param value and assignTo both show the value is passed to the controller and the PageReference  populate correctly based on my TestMethod.  However, when the commandlink is executed on the live data, the URL has the variable name of the "value=" populate the URL, i.e. {!}.


ERROR MESSAGE: Id value {} is not valid for the User standard controller URL:{} PORTIONS OF CONTROLLER WITH DIFFERENT OPTIONS TRIED: public PageReference UserSelected () { String s = apexPages.currentPage().getParameters().get('UserId'); PageReference retPage = new PageReference ('/apex/forecastquota?id=' + s); OR PageReference retPage = new PageReference ('/apex/forecastquota?id=' + SelectedUserId); OR PageReference retPage = Page.forecastquota; retPage.getParameters().put('Id',SelectedUserId); OR PageReference retPage = Page.forecastquota; retPage.getParameters().put('Id',s); retPage.setRedirect(true); return retPage; } public String getSelectedUserId() { return SelectedUserId; } public void setSelectedUserId(String s) { SelectedUserId = s; }


<apex:page standardController="User" extensions="ForecastQuotaInit"> <apex:sectionHeader title="Forecast and Quotas"/> <apex:form id="form1"> <apex:pageMessages /> <apex:outputPanel id="SearchUsers" > <apex:pageBlock title="User:" mode="edit" > <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:outputLabel for="searchText">User Name Search</apex:outputLabel> <apex:panelGroup > <apex:inputText id="searchText" value="{!searchText}"/> <apex:commandButton value="Go!" action="{!doSearch}" rerender="SearchUsers" status="status"/> </apex:panelGroup> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="User Selected:" for="User_Name"/> <apex:outputText value="{!UserName}" id="User_Name" rendered="{!NOT(ISNULL(UserId))}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:actionStatus id="status" startText="Retrieving Users..."/> </apex:pageBlock> <apex:pageBlock title="User:" mode="edit" > <apex:pageBlockTable value="{!results}" var="uu" rendered="{!NOT(ISNULL(results))}" > <apex:column > <apex:commandLink action="{!UserSelected}" value="{!uu.Name}" > <apex:param name="UserId" value="{}" assignTo="{!SelectedUserId}"/> </apex:commandLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel> </apex:form> </apex:page>




Message Edited by Brian Conlon on 05-06-2009 02:44 PM
Message Edited by Brian Conlon on 05-06-2009 02:45 PM
Best Answer chosen by Admin (Salesforce Developers) 

1 more try, to give you the same answer, this time without forum-markup:

{} = nothing. It will be interpreted literally as {}. Use: {!} Mind the !


All Answers

HarmpieHarmpie{} should be{!}


The line of code I believe is causing the problem is posted below.  I am trying to pass the User Id back to the controller as a parameter in both value and assignTo. I am using both methods to see if either works.  In both cases, my testmethod system.debug shows the true User Id passed back to the controller when I use the currentpage().getparameters().get('UserId') and also the getSelectedUserId methods.  However, when it is executed live, I don't get the UserId passed to the page, but{}.  TestMethod and results below as well.


<apex:param name="UserId" value="{}" assignTo="{!SelectedUserId}"/>


TEST METHOD CODE: //CHECK UserSelected System.currentPageReference().getParameters().put('UserId',; PageReference tPageRefUserSelected = myPageConInit.UserSelected(); String tURL1 = tPageRefUserSelected.getURL(); String tURL2 = Page.ForecastQuota.getURL() + '?Id=' +; system.debug('@@@T1:URLs=' + tURL1 + '--' + tURL2); String sss = tPageRefUserSelected.getParameters().get('Id');

system.debug ('@@@@T1:apexPages.currentPage()=' + apexPages.currentPage()); system.debug ('@@@@T1:tPageRefUserSelected=' + tPageRefUserSelected); system.debug ('@@@@T1:tPageRefUserSelected.getParams=' + sss); TEST RESULTS: 20090507123456.941:Class.ForecastQuotaInit.t1: line 235, column 9:

@@@T1:URLs=/apex/forecastquota?Id=00550000000mzRgAAI--/apex/forecastquota?Id=00550000000mzRgAAI 20090507123456.941:Class.ForecastQuotaInit.t1: line 239, column 9:

@@@@T1:apexPages.currentPage()=System.PageReference[/apex/forecastquotainit?UserId=00550000000mzRgAAI] 20090507123456.941:Class.ForecastQuotaInit.t1: line 240, column 9: @@@@T1:tPageRefUserSelected=System.PageReference[/apex/forecastquota?Id=00550000000mzRgAAI] 20090507123456.941:Class.ForecastQuotaInit.t1: line 241, column 9: @@@@T1:tPageRefUserSelected.getParams=00550000000mzRgAAI



1 more try, to give you the same answer, this time without forum-markup:

{} = nothing. It will be interpreted literally as {}. Use: {!} Mind the !


This was selected as the best answer
That did it.  I can't believe I missed the "!".  You look at your code so long and gloss over the syntax.  Thank you.