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
BManojKumarBManojKumar 

Record Type Selection Page Over riding

Hi All,

 

Good Day.

 

I would like to override the opportunity creation page for a particular record type.

I have 2 visual force pages "recordTypeSelect" and "opportunityPage". The below are my visual force pages.

 

recordTypeSelect :

 

<apex:page standardController="Opportunity" extensions="SaveClass" action="{!Redirect}">
<h1> Opportunity Record Type Select </h1>
</apex:page>

 

opportunityPage :

 

<apex:page StandardController="Opportunity" extensions="SaveClass">
<apex:pageBlock >
<apex:form >
<table>
<tr>
<td>Opportunity Name</td><td><apex:inputField required="true" value="{!Opportunity.Name}"/></td><td></td>
<td>CloseDate</td><td><apex:inputField required="true" value="{!Opportunity.CloseDate}"/></td>
</tr>
<tr>
<td>Account Name</td><td><apex:inputField required="true" value="{!Opportunity.AccountId}"/></td><td></td>
<td>StageName</td><td><apex:inputField required="true" value="{!Opportunity.StageName}"/></td>
</tr>
<tr><td>Inquiry Number</td><td><apex:inputField value="{!Opportunity.Inquiry_Number__c}"/></td></tr>

<tr><td>Product</td><td><apex:inputField required="true" value="{!Opportunity.Product__c}"/></td></tr>
<tr><td>Engine Model - Primary</td><td><apex:inputField required="true" value="{!Opportunity.Engine_Model_Primary__c}"/></td></tr>
<tr><td><apex:commandButton action="{!save}" value="Save"/><apex:commandButton action="{!cancel}" value="Cancel"/></td></tr>
</table>
</apex:form>
</apex:pageBlock>

</apex:page>
 

 

SaveClass:

public with sharing class SaveClass {

    public SaveClass(ApexPages.StandardController controller) {

    }

 

    public PageReference cancel() {
        PageReference pr = new PageReference('/006/o');
        pr.setRedirect(true);
        return pr;
    }
    
    public pagereference Redirect()
    {
       String rt = ApexPages.currentPage().getParameters().get('RecordType');
       if(rt.equals('012Q0000000CmCZ'))
      {
         String optyURL2 = '/apex/opportunityPage';
         pagereference pageref = new pagereference(optyURL2);
         pageref.setredirect(true);
         return pageref;
      }
      else
      {
         String optyURL2 = '/006/e?retURL=%2F006%2Fo&RecordType=012300000004ISs&ent=Opportunity';
         pagereference pageref = new pagereference(optyURL2);
         pageref.setredirect(true);
         return pageref;  
      }
      
    }
   
}

 

 

I have 6 types of recordtypes. I am overriding the "New" button in the opportunity home page with "recordTypeSelect" vf page.  So, Whenever the user selects the record type from the drop down , he will be redirected as shown in the "SaveClass". I have created a code like , whenever a user is selecting the particular recordtype he will redirected to the vf page "opportunityPage". otherwise he will redirected to a standard opportunity creation page.

 

What I need is , I am able to redirect the user to "opportunityPage" vf page , when he is selecting the particular recordtype. But I am not able to redirect him to the standard opportunity creation page when other record type is selected. The page is keep on refreshing and showing the "recordTypeSelect" vf page alone.

 

How can I fix this..?

 

Thanks in Advance.

 

Manoj.

Best Answer chosen by Admin (Salesforce Developers) 
BManojKumarBManojKumar

Hi All, I have found the solution for this bug. I just edited the "SaveClass" as below and it is working fine now.

 

SaveClass :

public with sharing class SaveClass{

 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 SaveClass(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 == '012Q0000000CmCZ') {
   returnURL = new PageReference('/apex/opportunityPage');
  }
  else {
   returnURL = new PageReference('/006/e');
  }

  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('/006/o');
          pr.setRedirect(true);
          return pr;
     }


}

 

 

Good Day.

 

Manoj.

All Answers

BManojKumarBManojKumar

Hi All, I have found the solution for this bug. I just edited the "SaveClass" as below and it is working fine now.

 

SaveClass :

public with sharing class SaveClass{

 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 SaveClass(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 == '012Q0000000CmCZ') {
   returnURL = new PageReference('/apex/opportunityPage');
  }
  else {
   returnURL = new PageReference('/006/e');
  }

  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('/006/o');
          pr.setRedirect(true);
          return pr;
     }


}

 

 

Good Day.

 

Manoj.

This was selected as the best answer
Che SFDCChe SFDC
Hi Manoj,
Could you please share test class associated with this extension?

Thanks,
gonzalolgonzalol
Hi Chetan,
Did you ever get the test class for this?
ManojjenaManojjena
Hi All,
I am facing a problem like when I have given recordType access to some profile and Skip Record Type Selection Page check check box uncheck then it is not executing the page .

Can any one suggest me some tips .
Thanks
Manoj