[SalesForce] Redirect to Visualforce Page After Record Type Chosen

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 button 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 remaining 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(ApexPages.currentPage().getParameters().get('RecordType') == '012L0000000DPwQ'){
            PageReference pageRef = new PageReference('/apex/VF_CaseDetail');
            return pageRef;
        }
        else{
            PageReference pageRef2 = new PageReference('https://cs8.salesforce.com/500/e?def_account_id='+c1.AccountId+'&RecordType='+c1.RecordTypeId+'ent=Case&nooverride=1');

            return pageRef2;
        }
    }
}

Error Message (Else Condition):

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.

Best Answer

In your CaseRedirect method you need to add the nooverride parameter to the URL so Salesforce knows not to send you to the VF page. Your method should look like this:

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&nooverride=1');

      return pageRef2;
  }
}

Here's a good article that explains this in more detail: http://blog.jeffdouglas.com/2008/11/14/redirecting-users-to-different-visualforce-pages/

Related Topic