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
Che SFDCChe SFDC 

Help with Record Type Redirect

Dear all, I`m new to apex and I need help with issue below. I have a "New Case" custom button on Opportunity record which allows me to create Case. When clicked on "New Case" button, I can select record type and page gets redirected to standard page or visualforce page using redirect class below. Code works fine but I`m unable to auto-populate fields when record type with standard page is selected. Fields are not getting auto populated the way it happens with standard functionality. For example, I`m not able to auto-populate Opportunity Name, Stage or Close Date while creating new case record. Can someone please help? Any help is much appreciated. Thank you!

Redirect VF page
<apex:page standardController="Case" extensions="Redirect" action="{!Redirect}">

</apex:page>

Redirect class
 
public with sharing class Redirect{

    private Id id;


 private ApexPages.StandardController controller;
 public String retURL {get; set;}
 public String saveNewURL {get; set;}
 public String rType {get; set;}
 public String cancelURL {get; set;}
 public String ent {get; set;}
 public String confirmationToken {get; set;}


 public Redirect(ApexPages.StandardController controller) {

  this.controller = controller;
  retURL = ApexPages.currentPage().getParameters().get('retURL');
  rType = ApexPages.currentPage().getParameters().get('RecordType');
  cancelURL = ApexPages.currentPage().getParameters().get('cancelURL');
  ent = ApexPages.currentPage().getParameters().get('ent');
  confirmationToken = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
  saveNewURL = ApexPages.currentPage().getParameters().get('save_new_url');
 }

 
 public PageReference redirect(){
  
  PageReference returnURL;
  // Redirect if Record Type corresponds to custom VisualForce page
  if(rType == '0121b0000009t60') {
   returnURL = new PageReference('/apex/vfcasepage');
  }
  else {
   returnURL = new PageReference('/500/e?nooverride=1');
  }

  returnURL.getParameters().put('retURL', retURL);
  returnURL.getParameters().put('RecordType', rType);
  returnURL.getParameters().put('cancelURL', cancelURL);
  returnURL.getParameters().put('ent', ent);
  returnURL.getParameters().put('_CONFIRMATIONTOKEN', confirmationToken);
  returnURL.getParameters().put('save_new_url', saveNewURL);
    returnURL.getParameters().put('nooverride', '1');
  returnURL.setRedirect(true);
  return returnURL;

 }

 public PageReference cancel() {
          PageReference pr = new PageReference('/500/o');
          pr.setRedirect(true);
          return pr;
     }


}


 
Best Answer chosen by Che SFDC
Saurabh BSaurabh B
Hi Che, try this;
 
public String oppname {get;set;}
  oppname = ApexPages.currentPage().getParameters().get('name of parameter');
​  returnURL.getParameters().put('name of parameter', oppname );
This should help you get parameter value.

All Answers

pconpcon
Let me make sure I understand your issue first.  You say that when you redirect to the second page (vfcasepage) you do not have any of your fields pre-populated (i'm assuming via URL manipulation)?  If this is correct, this is occuring because you are not copying over any of the URL parameters from the current page to your redirect page.  You would have to have a get from the current URL and then an additional put for your other fields you are trying to copy over.
Che SFDCChe SFDC
Hi Pcon, thank you for replying. Yes, I`m not able to autopopulate fields via URL manipulation. To be honest, I`m not sure how to get those URL parameters and put them over to next page (I tried several things but not helping). Could you please suggest changes in my code which would allow me to dot that? Appreciate it. 
 
Saurabh BSaurabh B
Hi Che, try this;
 
public String oppname {get;set;}
  oppname = ApexPages.currentPage().getParameters().get('name of parameter');
​  returnURL.getParameters().put('name of parameter', oppname );
This should help you get parameter value.
This was selected as the best answer
Che SFDCChe SFDC
Thank you, it works great! I`m able to pass parameter now.