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
Ram ArzaRam Arza 

Different VF Pages for different record types on the object

I have a scenario on a custom object called VM_Sales_Order__c with 6 record types named FAS, FSAL, ISAL, National Manager, Regional Manager and VP. Whenever I select a record type it should take me to its respective vf page. For example, when FAS record type is selected and new button is clicked it should take me to FAS VF Page. 

Below is the VF page and controller I wrote. Can someone check this code and let me know what would be the next step or if any changes required in this code.

My VF Page:
<apex:page standardController="Revenue_Reports__c" extensions="FAS_intercontroller" action="!FASpageRedirect">

</apex:page>
My Controller Code:
 
public with sharing class FAS_intercontroller {

public Revenue_Reports__c R1;

    public FAS_intercontroller (ApexPages.StandardController controller) {
    this.R1 = (Revenue_Reports__c)controller.getRecord();

    }
    
        public PageReference FASpageRedirect() {
        if(ApexPages.currentPage().getParameters().get('RecordType') == '012230000004KYF'){
            PageReference pageRef = new PageReference('/apex/RevenueReports_FAS_VfPge');
            return pageRef;
            }
             else if(ApexPages.currentPage().getParameters().get('RecordType') == '012230000004KYj'){
             PageReference pageRef1 = new PageReference('/apex/RevenueReports_FSAL_VFPage');
             return pageRef1;
             }
             else if(ApexPages.currentPage().getParameters().get('RecordType') == '012230000004KYP'){
             PageReference pageRef2 = new PageReference('/apex/RevenueReports_ISAL_VfPge');
             return pageRef2;
             }
             else if(ApexPages.currentPage().getParameters().get('RecordType') == '012230000004KYU'){
             PageReference pageRef3 = new PageReference('/apex/RevenueReports_NationalManager_VFPage');
             return pageRef3;
             }
             else if(ApexPages.currentPage().getParameters().get('RecordType') == '012230000004KYZ'){
             PageReference pageRef4 = new PageReference('/apex/RevenueReports_RegionalManager_VFPage');
             return pageRef4;
             }
             else if(ApexPages.currentPage().getParameters().get('RecordType') == '012230000004KYe'){
             PageReference pageRef5 = new PageReference('/apex/RevenueReports_VP_VFPage');
             return pageRef5;
             }
             
             return null;
             }
             }
Any help is appreciated.



 
Apoorv Saxena 4Apoorv Saxena 4
Hi Ram,

Your code seems fine.

Next step would be to override the standard 'New' button for the object 'Revenue_Reports__c' with your visuaforce page.
So go to your ''Revenue_Reports__c'' custom object, then go to 'Buttons, Links, and Actions' section, Click on Edit link next to 'New' button, the in Override with, select visualforce page and set this page.

That's it , now test it by clicking on New button.

Please let me know how this works for you, mark this as Solved if this helps you so that others can view it as a proper solution.

Thanks,
​Apoorv