I have a visualforce list page that lists opportunity products and some of their fields. One of these fields is a lookup to a custom object. On each row in the visualforce page, the user is given the option to lookup an existing record of the custom object or to create a new one. If the user chooses to create a new one, they are given a select list of the different record types, they select one and click Create.
Here is the section of code in my visualforce page where the select list is:
<apex:column headerValue="Record Type">
<apex:selectList value="{!RecordType}" multiselect="false" size="1">
<apex:selectOptions value="{!rectypes}"/>
</apex:selectList><br/>
</apex:column>
Here is the section of code in the controller that deals with the record types:
public List<SelectOption> getrectypes() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('','--Select Record Type --'));
for(RecordType rt:[select id,name from RecordType where sobjecttype='cust_object__c']){
options.add(new SelectOption(rt.id,rt.name));
}
return options;
}
public String getRecordType() {
return recType;
}
public void setRecordType(String recType) {
this.recType= recType;
}
Here's the problem: I'm having trouble referencing the value of the record type that is selected from the select list. Further down in my page I have the Create link. Once the user clicks create, I need the id of the record type in the controller so that I can redirect the user to the appropriate page layout. Any idea how to get this? Any help is appreciated!
VF page:
<apex:commandLink action="{!onCreate}" value="Create">
</apex:commandLink>
Controller:
public PageReference onCreate(){
return new PageReference('/a0W/e&RecordType=' + RecTypeID);
}