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
Asif Khan 44Asif Khan 44 

Redirecting to the VF page based on record type selected

I have a student custom object and i have two record types for that, i want to create a VF page where user can select the record type and after pressing a button on that same page he should get redirected to another VF page which contains fields according to the record type selected and there i can fill the details which should get reflected to the database.
object - Student__c
Record types - Technical and Non technical
Vijay NagarathinamVijay Nagarathinam
Hi Asif,

Check the condtion like this.

If(Recordtype.name == Technical){
    // Use the page reference method to redirect another visualforce page.
}

Let me know if you need any help regarding this.

Thanks,
Vijay
Naval Sharma4Naval Sharma4
Hi Asif,

 VF Page Code
<apex:form>
 <apex:selectlist value="{!recordTypeId}">
	<apex:selectOptions value="{!recordTypes}"></apex:selectOptions>
 </apex:selectlist> 
 
<apex:commandButton value="Show Students" action="{!redirectToNewPage}"/>   
</apex:form>

Controller Code
public string recordTypeId {get;set;}
Map<String, String> mapRecordTypes = new Map<String, String>();
public List<SelectOption> getRecordTypes(){
	List<SelectOption> options = new List<SelectOption>();
	
	for(RecordType rt : [SELECT Id, Name FROM RecordType WHERE SObjectType = 'Student__c']){
		options.add(new SelectOption(rt.Id, rt.Name));
		mapRecordTypes.put(rt.Id, rt.Name);
	}
	return options;
}

public PageReference redirectToNewPage(){
	if(mapRecordTypes.get(recordTypeId) == 'Technical')
		return new PageReference('\yourTechnicalPageName');
	else if(mapRecordTypes.get(recordTypeId) == 'Non Technical')
		return new PageReference('\yourNonTechnicalPageName');
}

Let me know if you need any help.

Thanks,
Naval
 
Asif Khan 44Asif Khan 44
Thanks Vijay And Naval for your input, i will try this method and let u know if this is working or not...

thanks,
Asif
Asif Khan 44Asif Khan 44
Hey i got this code working, but now what i want is that when i click on transfer button only the  outputpanel with id="pb" will be shown and MainPanel should not , i tried to negate the rend variable but its not working.
here is my code

<apex:page Standardcontroller="Student__c" Extensions="TransactionSiteController" >
   
    <apex:form >
        
        <apex:outputPanel id="MainPanel">
            <apex:pageBlock >
                
                <apex:outputPanel >  <!--rendered="{!rend}"-->
                    <apex:pageBlock >
                        {!rend}
                        <apex:pageBlockButtons location="bottom">
                            <apex:commandButton value="Transfer" action="{!editWithRecordType}" rerender="pb"  />
                        </apex:pageBlockButtons>
                        <apex:pageBlockSection collapsible="false" columns="1">
                            <apex:inputField value="{!Student__c.RecordTypeId}"/>
                            <apex:inputhidden value="{!Student__c.Last_Name__c}" />
                            <apex:inputhidden value="{!Student__c.First_Name__c}" />                       
                            <apex:inputhidden value="{!Student__c.Extra_Curricular__c}" />
                        </apex:pageBlockSection>
                    </apex:pageBlock>
                </apex:outputPanel>
                
                <apex:outputPanel id="pb">
                    <apex:pageBlock rendered="{!rend}">
                       
                        <apex:pageBlockSection columns="1">
                            <apex:inputField value="{!Student__c.First_Name__c}"/>
                            <apex:inputField value="{!Student__c.Last_Name__c}"/>
                            <apex:inputField value="{!Student__c.Subject__c}"/>
                            <apex:inputField value="{!Student__c.Extra_Curricular__c}"/>
                            <apex:commandButton action="{!save}" value="Update"/>
                            <apex:commandButton value="Back" onclick="window.history.go(-1)"/>
                        </apex:pageBlockSection>
                    </apex:pageBlock>
                </apex:outputPanel>
            </apex:pageBlock>  
        </apex:outputPanel>
        
        
    </apex:form>
</apex:page>



controller



public class TransactionSiteController {
    public Boolean rend { get; set; }
    public Student__c proxy { get; set; }
    
    public TransactionSiteController(ApexPages.StandardController controller) {
        
        rend = false;
       
        this.proxy = (Student__c)controller.getRecord();
        
    }
    

    public PageReference editWithRecordType() {
        rend = true;
        return null;
        PageReference nextPage = new PageReference('/apex/demo');
        nextPage.getParameters().put('RecordType', proxy.RecordTypeId);
        
        
        return nextPage;
    }
}