1

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.

2
  • What is not working? the second URL or that the else is never triggered? What is the standard behaviour for you?. Please clarify that in order to help you..
    – MANUELAN00
    Commented May 10, 2016 at 0:29
  • @MANUELANOO -- I updated my controller above with what I am currently using. The 2nd URL is the one that is not working. It now returns an error, which I have also included above. Any idea how to fix it?
    – J. Neilan
    Commented May 10, 2016 at 14:47

1 Answer 1

2

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/

3
  • Thanks. I did add that but now I get an error message (posted in my original post). Any idea why?
    – J. Neilan
    Commented May 10, 2016 at 14:50
  • 1
    You just seem to be missing an '&' before the ent parameter.
    – AslamK
    Commented May 10, 2016 at 16:24
  • @AslamK -- WOW, thanks!! That did the trick! Sometimes you just look at things too much and miss the obvious ;-)
    – J. Neilan
    Commented May 10, 2016 at 16:37

You must log in to answer this question.

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