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
SFDC9999SFDC9999 

Assign Record Type ID from a override Visual force page

I have a Override page for Case , Which redirects to a Visual force page if a certain record type is selected and if not it redirects to a standard page. This is working perfectly for redireting to the necessary page . Howewer when  it is directed to the visual force page the record type which was selected is not passed to the visual force page and it is causing issues with the Picklist values based on the record type. Visual force page always shows the default record type instead of the selected record type.

Here is my override page 
 
<apex:page standardController="Case" extensions="caseRedirect" tabStyle="Case" showheader="true" action="{!redirect}" />
public with sharing class caseRedirect {

private ApexPages.StandardController controller;
public String retURL {get; set;}
public String Type {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 String accountID {get; set;}
public String contactID {get; set;}

public caseRedirect(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');
    accountID = ApexPages.currentPage().getParameters().get('def_account_id');
    contactID = ApexPages.currentPage().getParameters().get('def_contact_id');

}

public PageReference redirect() {

    PageReference returnURL;

    // Redirect if Record Type corresponds to custom VisualForce page

    IF(rType == '012180000000DjD') {

        returnURL = new PageReference('/apex/CC_CaseEdit?Recordtype=012180000000DjD');

    }
  
    ELSE {

       returnURL = new PageReference('/500/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');

    IF (accountID != null){

        returnURL.getParameters().put('def_account_id', accountID);

    }

    IF (contactID != null){

        returnURL.getParameters().put('def_contact_id', contactID);

    }

    returnURL.setRedirect(true);
    return returnURL;

}

}
When VF opens up the record type is always default record type instead of the record type i selected .What am i missing

Thanks 

 
Tejpal KumawatTejpal Kumawat
Hi SFDC999,

Put snippet parameter from constructor to action method.
    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');
    accountID = ApexPages.currentPage().getParameters().get('def_account_id');
    contactID = ApexPages.currentPage().getParameters().get('def_contact_id');

Regards
Tej Pal Kumawat
Skype : tejpalkumawat1991

If this answers your question mark Best Answer it as solution and then hit Like!
 
SFDC9999SFDC9999
HI Tej , I tried that and it still does not pass the record type ID