+ Start a Discussion
harish reddy 39harish reddy 39 

can we have one vf page for different recordtypes.

can we have one vf page for different recordtype,if so how to differentiate fields and picklist values.
N R SabhayaN R Sabhaya
Yes This is possible Let's See I give You Example

This is Custome Event VFpage With Diffrent Record Type ->
1) Go to Buttons, Links, and Actions on event -> Create New Actions -> Connect  yourVFPage

1) yourVFPage
<apex:page standardController="Event" extensions=yourVFPageController" action="{!redirectToNewVFPage}" >
</apex:page>

2)

public with sharing class yourVFPageController
{
    Public string recordTypeId;
    public Event evt{get; set;}
    
    public yourVFPageController(ApexPages.StandardController acon)
    {
         this.evt = (Event)acon.getRecord();
    } 
    
    public Pagereference redirectToNewVFPage()
    {
        Pagereference pg = null;
        string CommunityEventid = General_Configuration_Setting__c.getOrgDefaults().Community_Event_Record_Type_ID__c;
        string CommunityFundRaisingEventRecordTypeId = General_Configuration_Setting__c.getOrgDefaults().Fundraising_Event_RT_id__c;
        
        recordTypeId = ApexPages.CurrentPage().getParameters().get('RecordType');
        if(recordTypeId != null)
        {    
            if(recordTypeId == CommunityEventid || recordTypeId == CommunityFundRaisingEventRecordTypeId)
            {
                pg = Page.CreateCommunityEventVFPage;   // This is Your Custome VF Page for multiple Record type
            }
            else
            {
                string sfdcURL = URL.getSalesforceBaseUrl().toExternalForm()+ '/00U/e?RecordType='+recordTypeId+'&ent=Event&nooverride=1';
                System.debug('=========sfdcURL========' + sfdcURL);                
                pg = new PageReference(sfdcURL);
            }
            
            pg.getParameters().put('RecordType', recordTypeId);
            pg.setRedirect(true);
            return pg;
        }
        return null;
    }
}

Please let me know if you have any query.
Please mark it as best Answer if you find it helpful.

Thank You
Nikunj Sabhaya