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
Amita TatarAmita Tatar 

Override Record Type selection with custom page

Hi all,

I want to know whether we can override a particular record type page with a custom VF page? If yes how can we do that. Please help me
Siddharth ManiSiddharth Mani
You can override "New" button. Lots of references available for that. Once you override "New" button you can make it redirect to a VF Page (instead of standard New Record Page or Record Type Page) which is what you want to achieve I believe!
Medhya MahajanMedhya Mahajan
Hi Amita, 

You will have to override your New Button on the object and select a VF page with a controller ( refer link ) where to set your conditional redirection.

Also, you need to keep your "Skip record type seletion page " checkbox unchecked when you override the new button.

See link for reference:

http://www.topalovich.com/2009/08/force-com-tip-new-button-override-to-assign-visualforce-page-to-specific-record-type-using-native-apex-code/

Mark solved if this helps.

Regards
Medhya Mahajan
Amita TatarAmita Tatar
public with sharing class OrderRedirectExtensionController{
public Id strRecordTypeId{get;set;}
public Order orderObj{get;set;}
public RecordType recordType{get;set;}
List<RecordType> lstred{get;set;}
public OrderRedirectExtensionController(ApexPages.StandardController controller ){
strRecordTypeId= apexpages.currentpage().getparameters().get('RecordType');

Order orderObj = new Order();
orderObj.RecordTypeId = strRecordTypeId;

system.debug('****strRecordTypeId*********'+strRecordTypeId);
lstred=[select id,Name from RecordType where id=:strRecordTypeId];
system.debug('****lstred*********'+lstred);

}

public PageReference saveOrder(){
 insert orderObj ;
 PageReference pageRef = new PageReference('/'+orderObj.id);
 pageRef.setRedirect(true); 
 return pageRef ;

}
}
Guys This is my apex class, whenever i select the record type it is not determining the record type value . Can u please help?
 
Medhya MahajanMedhya Mahajan
Hi Amita, 

The code seems to be correct. Can you provide me further details ? 

When you Select the record type and move to the VF ( Can you see the Record Type in the URL ) ??

Regards
Medhya Mahajan
Amita TatarAmita Tatar
Hi Medhya,

yes i am able to see the record type in the URL,but its not displaying on the page properly. Also i have picklist values for each record type. They are also not retrieved properly
Amita TatarAmita Tatar
Medhya,
I have overriden the new button. Where is the checkbox for "skip record type selection" page
Medhya MahajanMedhya Mahajan
User-added image

It's available on the Override option of new button.

Also, can you share the code for VF with me ???
 
Amita TatarAmita Tatar
Yes sure.
<apex:page standardController="Order"  extensions="OrderRedirectExtenController" showHeader="true">
<apex:form >
<apex:messages />

 <style>
 .activeTab {background-color: #236FBD; color:white;
 background-image:none}
 .inactiveTab { background-color: lightgrey; color:black;
  background-image:none}
</style>


<apex:pageBlock title="Order edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>

</apex:pageBlockButtons>
<apex:pageBlockSection title="Order Information" columns="2">

<apex:inputField value="{!order.AccountId}" required="true"/>
<apex:inputField value="{!order.RecordTypeId}"/>
<apex:inputField value="{!order.OpportunityId}"/>
<apex:inputField value="{!order.Equipment_Name__c}" />
<apex:inputField value="{!order.PoDate}"/>
<apex:inputField value="{!order.PoNumber}"/>
<!-- <apex:inputField value="{!order.OrderNumber}"/> -->
<apex:inputField value="{!order.Type}"/>
<apex:inputField value="{!order.Order_Reason__c}"/>
<apex:inputField value="{!order.Order_Start_Date__c}" required="true"/>
<apex:inputField value="{!order.EffectiveDate}" label="Order End Date"/>
<apex:inputField value="{!order.Status}"/>
<apex:inputField value="{!order.Case__c}"/>
<apex:inputField value="{!order.Payment_Options__c}"/>
<apex:inputField value="{!order.Signature_Required__c}"/>
<apex:inputField value="{!order.Delivery_Block_Status__c}"/>
<apex:inputField value="{!order.TotalAmount}"/> 
</apex:pageblockSection>

<apex:pageblockSection title="Other Information" columns="2">
<apex:inputField value="{!order.ContractId}"/>
<apex:inputField value="{!order.CustomerAuthorizedById}"/>
<apex:inputField value="{!order.CustomerAuthorizedDate}"/>
<apex:inputfield value="{!order.Ship_To_Name__c}"/>
<apex:inputfield value="{!order.Shipping_Method__c}"/>
<apex:inputfield value="{!order.Shipping_Account_Number__c}"/>
<apex:inputField value="{!order.Description}"/>
</apex:pageblockSection>




</apex:pageBlock>

</apex:form>
</apex:page>

 
Amita TatarAmita Tatar
<apex:page standardController="Order" showHeader="true" extensions="OrderRedirectExtenController"
action="{!IF(recordType.Name=='Parts - Billable',
URLFOR('https://c.cs20.visual.force.com/apex/OrderCustomPage1',$ObjectType.Order,null,true),


 if(recordType.Name=='Parts - Warranty',URLFOR('https://c.cs20.visual.force.com/apex/OrderPartsWarranty?retURL=%2F006%2Fo&RecordType='+RecordType.Id,$ObjectType.Order,null,true),

if(recordType.Name=='Parts - Free Of Charge',URLFOR('https://c.cs20.visual.force.com/apex/OrderPartsFreeOfCharge',$ObjectType.Order,null,true),
if(recordType.Name=='Service',URLFOR('https://c.cs20.visual.force.com/apex/OrderService',$ObjectType.Order,null,true),




null))))

}">
</apex:page>
This is the page with which i have overridden 'new' button
 
Medhya MahajanMedhya Mahajan
Amita,

Change you code of controller like this :

You were not assigning the value to varibale recordType and your are redirecting based on that only.
public with sharing class OrderRedirectExtensionController{
public Id strRecordTypeId{get;set;}
public Order orderObj{get;set;}
public RecordType recordType{get;set;}
List<RecordType> lstred{get;set;}
public OrderRedirectExtensionController(ApexPages.StandardController controller ){
strRecordTypeId= apexpages.currentpage().getparameters().get('RecordType');

Order orderObj = new Order();
orderObj.RecordTypeId = strRecordTypeId;

system.debug('****strRecordTypeId*********'+strRecordTypeId);
lstred=[select id,Name from RecordType where id=:strRecordTypeId];
system.debug('****lstred*********'+lstred);
recordType = lstred[0];
}

public PageReference saveOrder(){
 insert orderObj ;
 PageReference pageRef = new PageReference('/'+orderObj.id);
 pageRef.setRedirect(true); 
 return pageRef ;

}
}

Hope this helps.

Regards
Medhya Mahajan
 
Amita TatarAmita Tatar
Hi Medhya,
 I tried with this code. Its still the same
Ashu sharma 38Ashu sharma 38
Hello All,

As  I am stucking the same issue,when i select the particular record type the cutsom vf page should be display but its not getting.
I am referring this link:https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F0000000DC4AIAW
Please find the code:



public class opportunityinsert {
    public boolean activeStats                     {set;get;}
    public string name                         {set;get;}
    public decimal amount                     {set;get;}
    public List<Selectoption> type                 {set;get;}
    public List<Selectoption> leadsource             {set;get;}
    public List<Selectoption> StageName             {set;get;}
    public string NextStep                         {set;get;}
    public string OrderNumber                     {set;get;}
    public string CurrentGenerator                 {set;get;}
    public string TrackingNumber                 {set;get;}
    public string MainCompetitor                 {set;get;}
    public List<Selectoption> Deliverystatus             {set;get;}
    public date dat                             {set;get;}
    public decimal Probability                      {set;get;}
    public string Description                     {set;get;}
    public string s                             {set;get;}
    public string t                             {set;get;}
    public string u                             {set;get;}
    public string v                             {set;get;}
    
    public opportunityinsert(Apexpages.StandardController controller){
        Opportunity op = new Opportunity();
        op.Amount = amount;
        op.CloseDate = dat;
        op.Name = name;
        op.NextStep = NextStep;
        op.Probability = Probability; 
        StageName=new List<SelectOption>();
        StageName.add(new SelectOption('--None--','--None--'));
        StageName.add(new SelectOption('Prospecting','Prospecting'));
        StageName.add(new SelectOption('Qualification','Qualification'));
        StageName.add(new SelectOption('Needs Analysis','Needs Analysis'));
        StageName.add(new SelectOption('Value Proposition','Value Proposition'));
        StageName.add(new SelectOption('Id. Decision Makers','Id. Decision Makers'));
        StageName.add(new SelectOption('Perception Analysis','Perception Analysis'));
        StageName.add(new SelectOption('Proposal/Price Quote','Proposal/Price Quote'));
        StageName.add(new SelectOption('Negotiation/Review','Negotiation/Review'));
        StageName.add(new SelectOption('Closed Won','Closed Won'));
        StageName.add(new SelectOption('Closed Lost','Closed Lost'));
        
        type=new List<SelectOption>();
        type.add(new SelectOption('--None--','--None--'));
        type.add(new SelectOption('Existing Customer - Upgrade','Existing Customer - Upgrade'));
        type.add(new SelectOption('Existing Customer - Replacement','Existing Customer - Replacement'));
        type.add(new SelectOption('Existing Customer - Downgrade','Existing Customer - Downgrade'));
        type.add(new SelectOption('New Customer','New Customer'));
        leadsource=new List<SelectOption>();
        leadsource.add(new SelectOption('--None--','--None--'));
        leadsource.add(new SelectOption('Web','Web'));
        leadsource.add(new SelectOption('Phone Inquiry','Phone Inquiry'));
        leadsource.add(new SelectOption('Partner Referral','Partner Referral'));
        leadsource.add(new SelectOption('Purchased List','Purchased List'));
        leadsource.add(new SelectOption('Other','Other'));
        
        op.OrderNumber__c = OrderNumber;
        op.CurrentGenerators__c = CurrentGenerator;
        op.MainCompetitors__c = MainCompetitor;
        Deliverystatus=new List<SelectOption>();
        Deliverystatus.add(new SelectOption('--None--','--None--'));
        Deliverystatus.add(new SelectOption('In progress','In progress'));
        Deliverystatus.add(new SelectOption('Yet to begin','Yet to begin'));
        Deliverystatus.add(new SelectOption('Completed','Completed'));
        op.TrackingNumber__c = TrackingNumber;
        
        op.Description = Description;
        
    }
    
    public void  saveMe(){
        Opportunity Op= new Opportunity();
        Op.Amount = amount;
        Op.IsPrivate = activeStats;
        Op.CloseDate = dat;
        Op.Name = name;
        Op.NextStep = NextStep;
        Op.StageName = s;
        Op.Type = t;
        Op.Probability = Probability;
        Op.LeadSource = u;
        Op.OrderNumber__c = OrderNumber;
        Op.CurrentGenerators__c = CurrentGenerator;
        Op.MainCompetitors__c = MainCompetitor;
        Op.DeliveryInstallationStatus__c = v;
        Op.TrackingNumber__c = TrackingNumber;
        Op.Description = Description;
        insert Op;
        apexpages.Message msg = new apexpages.Message(apexpages.Severity.CONFIRM, 'Record Inserted Successfully..');
        apexpages.addMessage(msg);
        
        amount = null;
        activeStats = null;
        dat = null;
        name = null;
        NextStep = null;
        s = null;
        t = null;
        Probability = null;
        u = null;
        OrderNumber = null;
        CurrentGenerator = null;
        MainCompetitor = null;
        v = null;
        TrackingNumber = null;
        Description = null;
    }
    public void  Cancel(){
        
        amount = null;
        activeStats = null;
        dat = null;
        name = null;
        NextStep = null;
        s = null;
        t = null;
        Probability = null;
        u = null;
        OrderNumber = null;
        CurrentGenerator = null;
        MainCompetitor = null;
        v = null;
        TrackingNumber = null;
        Description = null;
        
        apexpages.Message msg = new apexpages.Message(apexpages.Severity.ERROR,'Please Try Again');
        apexpages.addMessage(msg);
    }
    
    
    public pagereference redirectPage(){
        
        Opportunity opp=new Opportunity();
        PageReference oppPage ;
        if(opp.recordTypeId=='0127F000000BbjNQAS')// Record type Id
        {
            oppPage = new PageReference('/apex/opportunityinsert?core.apexpages.request.devconsole=1' );
            oppPage.setRedirect(true);
        }
         return oppPage;
        
    }

    
    
}


 VF page
========
<apex:page standardController="Opportunity" extensions="opportunityinsert" docType="html-5.0" action="{!redirectPage}">
    <apex:form >
        <apex:sectionHeader title="Opportunity Edit" subtitle="New Opportunity" help="https://help.salesforce.com/articleView?err=1&id=opportunities.htm&type=5"/>
        <apex:pageBlock title="Opportunity Edit" mode="edit">
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockButtons location="both">
                <apex:commandButton value="Save" action="{!saveMe}"/>
                <apex:actionStatus id="actStatusId" >
                    <apex:facet name="start" >
                        <apex:image url="https://kberkery.com/wp-content/uploads/2017/08/site_loading.gif" height="50" width="50"/>
                    </apex:facet>
                </apex:actionStatus>
                <apex:commandButton value="Save & New" />
                <apex:commandButton value="Cancel"  action="{!Cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection collapsible="false" columns="2" title="Opportunity Information">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Opportunity Owner"/>
                    <apex:outputText value="{!$User.FirstName&' '&$User.LastName}">
                    </apex:outputText>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Amount"/>
                    <apex:inputText value="{!amount}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Private"/>
                    <apex:inputCheckbox value="{!activeStats}"/>
                </apex:pageBlockSectionItem>   
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Close Date"/>
                    <apex:outputPanel>
                        <div class="requiredInput">
                            <div class="requiredBlock"></div>
                            <apex:input type="date" value="{!dat}" required="true"/>
                        </div>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>   
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Opportunity Name" />
                    <apex:outputPanel>
                        <div class="requiredInput">
                            <div class="requiredBlock"></div>
                            <apex:inputText value="{!name}"/>
                        </div>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Next Step"/>
                    <apex:inputText value="{!NextStep}"/>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Account Name"/>
                    <apex:inputField value="{!Opportunity.accountId}"/>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Stage"/>
                    <apex:outputPanel>
                        <div class="requiredInput">
                            <div class="requiredBlock"></div>
                            <apex:selectList size="1" value="{!s}">
                                <apex:selectOptions value="{!StageName}"/>
                            </apex:selectList>
                        </div>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Type"/>
                    <apex:selectList size="1" value="{!t}">
                        <apex:selectOptions value="{!type}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Probability (%)"/>
                    <apex:inputText value="{!Probability}"/>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Lead Source"/>
                    <apex:selectList size="1" value="{!u}">
                        <apex:selectOptions value="{!Leadsource}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Primary Campaign Source"/>
                    <apex:inputField value="{!Opportunity.campaignid}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection collapsible="false" columns="2" title="Additional Information">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Order Number"/>
                    <apex:inputText value="{!OrderNumber}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Main Competitor(s)"/>
                    <apex:inputText value="{!MainCompetitor}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Current Generator(s)"/>
                    <apex:inputText value="{!CurrentGenerator}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Delivery/Installation Status"/>
                    <apex:selectList size="1" value="{!v}">
                        <apex:selectOptions value="{!Deliverystatus}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Tracking Number"/>
                    <apex:inputText value="{!TrackingNumber}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection collapsible="false" columns="2" title="Description Information">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Description"/>
                    <apex:inputTextarea value="{!Description}" cols="70" rows="6"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>           
    </apex:form>
</apex:page>
===========