Record Type Redirect to VisualForce Page Using Button Override

This tip originally appeared on SaaSkatoon, the SaaS and cloud computing blog from Delivered Innovation.

Use Case: Client has multiple call centers supporting various product lines; support team ‘A’ requires a custom Wizard to rapidly search for and collect details for the Case record that the standard Salesforce search interface cannot provide.

Solution: While you can assign a specific Page Layout to a specific Record Type and embed VisualForce pages in the object Detail view, currently salesforce.com does not support embedded VisualForce Pages in the Edit view of a Page Layout; likewise, salesforce.com does not support custom VisualForce pages for specific Record Types. The solution is to “intercept” the command to create a new record in an Object before Salesforce processes it, and this is accomplished with a 1-line VisualForce page and a StandardController extension that pulls and analyzes certain URL parameters to enhance the out-of-the-box process routing capabilities of Salesforce.

The VisualForce Page code:

<apex:page standardController="Case" extensions="caseRedirect" tabStyle="Case" showheader="true" action="{!redirect}" />

The Apex controller extension:

public with sharing class caseRedirect {

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 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 == 'xxxxxxxxxxxxxxx') {

returnURL = new PageReference('/apex/insert_VF_Page_Here');

}

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;

}

2 comments to Record Type Redirect to VisualForce Page Using Button Override

  • Manoj Kumar

    Hi ,

    I have found the reason for the bug. It is because I have not set this record type as the default record type for the user profile.

    It is working fine now.

    Thanks a lot.

    Manoj

  • Manoj Kumar

    Hi,

    This code is very useful and it fixed my bug in record type redirecting.
    But still i am facing a bug that if I am over riding with my visual force page , in the opportunity detail page , the record type is coming as the default one and not the desired one.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>