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
John Neilan 2John Neilan 2 

Redirect to Visualforce Page After Record Type Chosen

Hello,

I am trying to redirect users to a VF page after the record type is chosen when creating a new Case.  If a particular Record Type is chosen, the use should be brought to a VF page, anything else should default to the normal behavior after a Record Type is selected.  I have the VF page below overriding the New bustton on Cases, and the controller to go with it.  The users are being re-directed to the VF page, but the other part is not working as it is still remaning on the VF page re-direct.  Can anyone help me get the default behavior in the controller?  Thanks,

VF Page:
<apex:page standardcontroller="Case" extensions="VF_Controller_CasePgLayout" action="{!CaseRedirect}"/>

Controller:
//Controller to Override Case creation
public with sharing class VF_Controller_CasePgLayout{

public Case c1;

    public VF_Controller_CasePgLayout(ApexPages.StandardController myController){
        this.c1 = (Case)myController.getRecord();
    }

    public PageReference CaseRedirect() {
        if(c1.RecordTypeId =='012L0000000DPwQ'){
            PageReference pageRef = new PageReference('/apex/VF_CaseDetail');
            return pageRef;
        }
        else{
            PageReference pageRef2 = new PageReference('/500/e?retURL=%2F'+c1.AccountId+'&def_account_id='+c1.AccountId+'&RecordType='+c1.RecordTypeId+'ent=Case');
            
            return pageRef2;
        }
    }
}

 
@Karanraj@Karanraj
For the new record creation you need to get the recordtype id from the page parameter and based on that you need to write the redirect page logic. Try with the below update code 
 
//Controller to Override Case creation
public with sharing class VF_Controller_CasePgLayout{

public Case c1;

    public VF_Controller_CasePgLayout(ApexPages.StandardController myController){
        this.c1 = (Case)myController.getRecord();
    }

    public PageReference CaseRedirect() {
        If(ApexPages.currentPage().getParameters().get('RecordType') != '012L0000000DPwQ'){
            PageReference pageRef = new PageReference('/apex/VF_CaseDetail');
            return pageRef;
        }
        else{
            PageReference pageRef2 = new PageReference('/500/e?retURL=%2F'+c1.AccountId+'&def_account_id='+c1.AccountId+'&RecordType='+c1.RecordTypeId+'ent=Case');
            
            return pageRef2;
        }
    }
}



 
John Neilan 2John Neilan 2
Thanks!  The redirect to the Visualforce page works, however when I try to redirect to the normal page that comes up after the Record Type (the Else condition), it still goes to a VF page.  Any idea how to fix that?
@Karanraj@Karanraj
Try adding no override=1 in the end of the url  Thanks, Karan
John Neilan 2John Neilan 2
OK.  Now I get an error message.  My line is:
 
PageReference pageRef2 = new PageReference('https://cs8.salesforce.com/500/e?def_account_id='+c1.AccountId+'&RecordType='+c1.RecordTypeId+'ent=Case&nooverride=1');

The error is:
Unable to Access Page
The value of the "id" parameter 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 resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.

Any idea?
Victor FelisbinoVictor Felisbino
Hope you are not doing this using lightening, it doenst work.
but here is how i got mine to work
PageReference outpage =  this.controller.edit();
//you can do some logic in here in case the recordtype selected needs to go to a visualforce page or whatever, just change the value of outpage

//after all the logic, you should do this
for(string key : System.currentPageReference().getParameters().keySet()){
            if(!key.equalsIgnoreCase('view') && !key.equalsIgnoreCase('sfdc.override') && !key.equalsIgnoreCase('id')) {
                outpage.getParameters().put(key, System.currentPageReference().getParameters().get(key));
            }
        }
       outpage.getParameters().put('nooverride','1');
       outpage.setRedirect(true);   
       return outpage;