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
jpb@uhcjpb@uhc 

URL redirect after Save()

Ok, here is the scenario...we want to replace our standard Convert button with a custom button that will first call a VF page that has a single field that will be modified on the Lead. The VF page uses the standard Lead Controller and standard Save() method. We want to be able to then direct the user to the Leadconvert.jsp page after save. We created a custom Save() method using an extension class and the redirect works but the problem is I don't know how to pass parameters to populate the URL correctly. Here is the VF page:

<apex:page standardController="Lead" extensions="TeamTrackFlag" sidebar="false">
  <apex:sectionHeader title="Edit Create Team Track Flag"
                      subtitle="{!lead.name}"/>
  <apex:form >
    <apex:pageBlock title="Edit Lead" id="thePageBlock"
                    mode="edit">
      <apex:pageMessages />
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Cancel" action="{!cancel}"/>
      </apex:pageBlockButtons>
        <apex:inputField value="{!Lead.Create_TeamTrack__c}" 
              required="true"/>
        <apex:inputField value="{!Lead.ID}" rendered="false" />
    </apex:pageBlock>
  </apex:form> 
</apex:page>

Here is the class:

public class TeamTrackFlag{
    ApexPages.StandardController controller;
        public TeamTrackFlag(ApexPages.StandardController con){
                controller = con;
                     }
                                     
public PageReference save()
 {        controller.save();
         PageReference redirecturl = new PageReference('/lead/leadconvert.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}&noopptt={!Lead.Company}-{!Lead.Name}')
         return redirecturl;
             }}

This is the error I get:

Unable to Access Page
Invalid parameter value "{!Lead.Id}" for parameter "id".

Error: The value of the parameter specified above contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and re-submit. If the error still persists, please report it to our Customer Support team and provide the URL of the page you were requesting as well as any other related information.

 
And the URL looks like this:

https://cs3.salesforce.com/lead/leadconvert.jsp?id=%7B%21Lead.Id%7D&noopptt=%7B%21Lead.Company%7D-%7B%21Lead.Name%7D&retURL=%2F%7B%21Lead.Id%7D

Help! I'm an analyst who doesn't do much coding, i'm hoping its a simple fix.
alexbalexb

You have some bad code there...

 

  PageReference redirecturl = new PageReference('/lead/leadconvert.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}&noopptt={!Lead.Company}-{!Lead.Name}')

 

The "{!something}" syntax is only readable by the VF parser/interpreter. The Apex script engine won't know what to do with it.

The PageReference constructor that you are trying to use will only take an expression that evaluates to a String. Try doing something like this instead:

 

//Specify each URL param separately

String redirectUrl = '/lead/leadconvert.jsp?retURL=';

String returnUrl = someLeadId;

String idParam = someLeadId;

String nooppttParam = someLeadCompanyName + '-' + someLeadName';

//Construct the return URL in an organized manner

redirectUrl = redirectUrl + '?retURL=' + returnUrl + '&id=' + idParam + '&noopptt=' + nooppttParam;

PageReference redirectPage = new PageReference(redirectUrl);

//Decide if you want to keep the viewState

redirectPage.setRedirect(true);//true = discard the viewState

//return the PageReference

return redirectPage;

 

 

You still need to fill in the someLead information - probably from the lead on the standard controller.

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_std.htm