+ Start a Discussion
San IndiaSan India 

How to assign VF page to record type

Hi Friends,

I have a requirement with 2 record types
when i choose X record type it should display opportunity standard page 
when i choose Y record type it should display VF Page with opportunity mandatory fields  

unable to do this , can any one help on this

Thanks
Himanshu ParasharHimanshu Parashar
You can write your  logic inside action method on page load and check if it is Y record type. if not you can redirect that to standard page.

Y record type visualforce page
 
<apex:page standardController="Opportunity" extension="yourextensionname" action="{!redirectPage}">

Y Controller extension
 
public pagereference redirectPage(){
//write your logic here
if(opp.recordTypeId=='X record type')
{
   PageReference oppPage = new PageReference(opp.id + '/e?retURL=%2F' + opp.id);
   oppPage.setRedirect(true);
   return oppPage;

}

}

 
Mahesh DMahesh D
Hi San,

Please find the solution for your issue:
 
<apex:page standardController="Opportunity" extensions="NewOppController" action="{!redirectPage}">
</apex:page>
public class NewOppController {
    Opportunity opp {get; set;}
    public NewOppController(ApexPages.StandardController controller) {
        opp = (Opportunity) controller.getRecord();
    }
    
    public PageReference redirectPage() {
        String rtStr = ApexPages.currentPage().getParameters().get('RecordType');
        Id rtId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Test RT').getRecordTypeId();
        String rtXStr = String.valueOf(rtId);
        System.debug('==================rtStr :'+rtStr);
        System.debug('==================rtXStr:'+rtXStr);
        if(rtXStr.contains(rtStr)) {
            return new PageReference('/apex/YouCustomerVFPage?field=12343');
        } else {
            return new PageReference('/apex/YouCustomerVFPage123');
        }
    }
}

Either wa you can't send it to standard page as we are overridding the New object it will be in infinite loop, if we pass it to Standard Functionalaity.

Please do let me know if it helps you.

Regards,
Mahesh

 
anil Kumaranil Kumar
Hi Mahesh,

Where we need include the visualforce page ?

Thanks,
Anil Kumar