+ Start a Discussion
Harsha ShriHarsha Shri 

render VF page based on record type selection

Hi All,
I have the followwing VF page and controller class
<apex:page standardController="test__c" extensions="Recordtypes" id="pg">
    <apex:form >
        <apex:pageBlock title="Recordtypes" id="pd">
            <apex:selectList size="1" value="{!RecordTypes}" >
                <apex:actionSupport event="onchange" reRender="panel1,panel2" />
                RecordTypes :  <apex:selectOptions value="{!RecordTypes}">
                
                </apex:selectOptions>
            </apex:selectList>
            <apex:outputPanel id="panel1">   
                  <apex:pageBlockSection rendered="{!RecordTypes=='R1'}" >
                     Field1 :  <apex:inputText />
                  </apex:pageBlockSection>
              </apex:outputPanel> 
            <apex:outputPanel id="panel2">   
                  <apex:pageBlockSection rendered="{!RecordTypes=='R2'}" >
                     Field2 :  <apex:inputText />
                  </apex:pageBlockSection>
              </apex:outputPanel> 
        </apex:pageBlock>
        
    </apex:form>
</apex:page>
 
public class Recordtypes {
    public list<selectoption> lstOfRectypes{set;get;}
    List<RecordType> recList;
    test__c t;
    ApexPages.StandardController controller;
    public Recordtypes (ApexPages.StandardController controller) {
        this.controller = controller;
        t = (test__c) Controller.getRecord();
        }
    public list<SelectOption> getRecordTypes() {
        list<SelectOption> options = new list<SelectOption>();
        for (list<RecordType> rts : [SELECT ID, name FROM RecordType WHERE SObjectType = 'test__c' ORDER BY name]) {
            for (RecordType rt : rts) {
                options.add(new SelectOption(rt.ID, rt.Name));
            } 
        }
        return options;
    }
    
}
I have written above code, to render VF page based on record type selection
when I am selecting selecting record type, VF page is not redering 
Please help me if any correction need to do for above code

Thanks in Advance
Best Answer chosen by Harsha Shri
v varaprasadv varaprasad

Hi Harsha,

Please check code.
 
<apex:page controller="Recordtypes" id="pg">
    <apex:form >
        <apex:pageBlock title="Recordtypes" id="pd">
            <apex:selectList size="1" value="{!selrecordtype}" >
                <apex:actionSupport event="onchange" reRender="panel1,panel2" />
                RecordTypes :  <apex:selectOptions value="{!lstOfRectypes}">
                
                </apex:selectOptions>
            </apex:selectList>
            <apex:outputPanel id="panel1">   
                  <apex:pageBlockSection rendered="{!selrecordtype=='International'}" >
                     Field1 :  <apex:inputText />
                  </apex:pageBlockSection>
            </apex:outputPanel>
            <apex:outputPanel id="panel2">   
                  <apex:pageBlockSection rendered="{!selrecordtype=='US Lead'}" >
                     Field2 :  <apex:inputText />
                  </apex:pageBlockSection>
              </apex:outputPanel> 
        </apex:pageBlock>
        
    </apex:form>
</apex:page>


==========================

public class Recordtypes {
    public list<selectoption> lstOfRectypes{set;get;}
    List<RecordType> recList;
    public string selrecordtype{set;get;}
    
    public Recordtypes(){
        system.debug('==selrecordtype=='+selrecordtype);
        lstOfRectypes =  new list<selectoption>();
        lstOfRectypes.add(new selectoption('None','None'));
        recList= new List<RecordType>([select id, name from recordtype where sobjecttype='Lead']);
        for(RecordType rd : recList){           
            lstOfRectypes.add(new selectoption(rd.name,rd.name));
        }
    }
}

Hope this helps you.

If it helps you.Please mark it as the best answer.


Thanks
Varaprasad

All Answers

v varaprasadv varaprasad

Hi Harsha,

Please check code.
 
<apex:page controller="Recordtypes" id="pg">
    <apex:form >
        <apex:pageBlock title="Recordtypes" id="pd">
            <apex:selectList size="1" value="{!selrecordtype}" >
                <apex:actionSupport event="onchange" reRender="panel1,panel2" />
                RecordTypes :  <apex:selectOptions value="{!lstOfRectypes}">
                
                </apex:selectOptions>
            </apex:selectList>
            <apex:outputPanel id="panel1">   
                  <apex:pageBlockSection rendered="{!selrecordtype=='International'}" >
                     Field1 :  <apex:inputText />
                  </apex:pageBlockSection>
            </apex:outputPanel>
            <apex:outputPanel id="panel2">   
                  <apex:pageBlockSection rendered="{!selrecordtype=='US Lead'}" >
                     Field2 :  <apex:inputText />
                  </apex:pageBlockSection>
              </apex:outputPanel> 
        </apex:pageBlock>
        
    </apex:form>
</apex:page>


==========================

public class Recordtypes {
    public list<selectoption> lstOfRectypes{set;get;}
    List<RecordType> recList;
    public string selrecordtype{set;get;}
    
    public Recordtypes(){
        system.debug('==selrecordtype=='+selrecordtype);
        lstOfRectypes =  new list<selectoption>();
        lstOfRectypes.add(new selectoption('None','None'));
        recList= new List<RecordType>([select id, name from recordtype where sobjecttype='Lead']);
        for(RecordType rd : recList){           
            lstOfRectypes.add(new selectoption(rd.name,rd.name));
        }
    }
}

Hope this helps you.

If it helps you.Please mark it as the best answer.


Thanks
Varaprasad
This was selected as the best answer
Harsha ShriHarsha Shri

Hi Varaprasad

you are a awesome developer
Please give me your mail id, I want to stay in touch with you

If you dont mind give me your mobile number

v varaprasadv varaprasad
Hi Harsha,

Above information is informative and helps you please mark it as best answer.


Thanks
Varaprasad
@For support :   Varaprasad4sfdc@gmail.com
Harsha ShriHarsha Shri

Hi Harsha,

I marked it as best answer