Override "New" (Salesforce Standard button) as per RecordType Selection
Following is the snippet of anonymous code which will help you to override Salesforce standard "New" button as per RecordType selected by user.
Here is the example for Overriding standard "New" button of Account Object(Any sObject) as per RecordType Selection.
Step 1:
Override your Standard button of Account Object("New") with custom visualforce page to which you want to redirect page.
Step 2:
Create one Custom Label with Name = "Custom_page_rectype". Put here your custom recordtype value (hard coded) For which you want to override conditionally.
Step 3:
Put action attribute in your visualforce page's <apex:page> tag as below.
Visualforce Page:
<apex:page standardController="Account" extensions="extCtrlRecordtyperedirect"
action="{!if(strRecTypeName==$Label.Custom_page_rectype,null,
URLFOR($Action.Account.Edit,
$ObjectType.Account,null,true))}">
This is Your custom visualforce Page
</apex:page>
Apex Class:
public class extCtrlRecordtyperedirect{
Public string strRecTypeName {get; set; }
public extCtrlRecordtyperedirect(ApexPages.StandardController controller) {
strRecTypeid = apexpages.currentpage().getparameters().get('RecordType');
if(strRecTypeid != null){
Schema.DescribeSObjectResult d = Schema.SObjectType.Account;
Map<Id,Schema.RecordTypeInfo> rtMapById = d.getRecordTypeInfosById();
strRecTypeName = rtMapById.get(strRecTypeid).getName();
}
}
Following is the snippet of anonymous code which will help you to override Salesforce standard "New" button as per RecordType selected by user.
Here is the example for Overriding standard "New" button of Account Object(Any sObject) as per RecordType Selection.
Step 1:
Override your Standard button of Account Object("New") with custom visualforce page to which you want to redirect page.
Step 2:
Create one Custom Label with Name = "Custom_page_rectype". Put here your custom recordtype value (hard coded) For which you want to override conditionally.
Step 3:
Put action attribute in your visualforce page's <apex:page> tag as below.
Visualforce Page:
<apex:page standardController="Account" extensions="extCtrlRecordtyperedirect"
action="{!if(strRecTypeName==$Label.Custom_page_rectype,null,
URLFOR($Action.Account.Edit,
$ObjectType.Account,null,true))}">
This is Your custom visualforce Page
</apex:page>
Apex Class:
public class extCtrlRecordtyperedirect{
Public string strRecTypeName {get; set; }
public extCtrlRecordtyperedirect(ApexPages.StandardController controller) {
strRecTypeid = apexpages.currentpage().getparameters().get('RecordType');
if(strRecTypeid != null){
Schema.DescribeSObjectResult d = Schema.SObjectType.Account;
Map<Id,Schema.RecordTypeInfo> rtMapById = d.getRecordTypeInfosById();
strRecTypeName = rtMapById.get(strRecTypeid).getName();
}
}