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}">


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');
  return returnURL;


 public PageReference cancel() {
          PageReference pr = new PageReference('/500/o');
          return pr;

  • So Case has a custom lookup field to Opportunity? Or are you copying the Opportunity fields (name, stagename, closeDate) into new custom fields on Case?
    – cropredy
    Commented Nov 23, 2015 at 2:08
  • did you filled all file in parameter. I think you have missed some parameter. Commented Nov 23, 2015 at 4:37

1 Answer 1


I was able to resolve this:

Public String oppname {get;set;} oppname = ApexPages.currentPage().getParameters().get('name of parameter'); ​ returnURL.getParameters().put('name of parameter', oppname );

Thank you everyone!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .