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
Tina DamTina Dam 

how to set the returl to a field listed on the visualforce page

I have a visualforce page that i'd like to have the "returl" to be directed to a field listed on the record (acc.Opportunity__c)
is that possible?

<apex:page Controller="RetUrlSearchController">
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockSection title="Criteria">
      <apex:outputLabel value="Enter Name Snippet"/>
      <apex:inputText value="{!nameQuery}"/>
      <apex:commandButton action="{!executeSearch}" value="Search"/>
    </apex:pageBlockSection>
   <apex:pageBlockTable value="{!accounts}" var="acc">
      <apex:column headerValue="Name">
         <apex:outputLink value="/{!acc.id}/e?retURL={!URLENCODE('/apex/InvoiceHeaderSearch?query='+nameQuery)}">{!acc.Name}</apex:outputLink>
      </apex:column>
      <apex:column value="{!acc.Invoice_Date__c}"/>
      <apex:column value="{!acc.Territory__c}"/>
   </apex:pageBlockTable>
</apex:pageBlock>

  </apex:form>
</apex:page>
Avidev9Avidev9
Can you elaborate a bit ? 
Its not very clear, are you trying to set anchor element ?
Avidev9Avidev9
Can you elaborate a bit ? 
Its not very clear, are you trying to set anchor element ?
James LoghryJames Loghry
I think you might be getting a little too fancy with the apex:outputLink.  Part of the issue it looks like you may encounter is that you will not see any updates to your nameQuery variable in the outputLink until after the page has rerendered.  Instead of your current approach, I'd suggest you create an action in Apex that redirects to the Account edit page with the specified retURL parameter.

Your apex action may look like the following:
public RetUrlSearchController{
 
    //Set from your visualforce commandLink param / assignTo attribute
    public Id selectedAccountId {get; set;}

    public PageReference redirectToAccountEditPage(){
        //Create a page reference for the account edit page.
        PageReference pageRef = new PageReference('/'+selectedAccountId+'/e');

        //Create a page reference to get the URL for the retURL parameter.
        PageReference retUrlPageRef = Page.InvoiceHeaderSearch;
        retUrlPageRef.getParameters().put('query',nameQuery);
        String retUrl = retUrlPageRef.getUrl(); // URL ENCODE THIS

        //Add the retURL param to the Account Edit Page URL
        pageRef.getParameters().put('retURL',retUrl);

        //Redirect the user to the Account Edit Page
        return pageRef;
    }
}

And you would replace your apex:outputLink tag with the following:

<apex:commandLink value="{!acc.Name}" action="{!redirectToAccountEditPage}">
    <apex:param name="selectedAccountId" assignTo="{!selectedAccountId}" value="{!acc.Id} />
</apex:commandLink>