You need to sign in to do that
Don't have an account?

Using Record Types on Visualforce pages
Hi Everyone,
I am trying to create a form wizard that allows users to submit Travel Request information. We have 7 different travel request types that each have their own record type. This functionality works correctly using the Case object, but when I try using our Travel_Request__c custom object it is not saving the record. Any help would be greatly appreciated !! Listed below is my controller
public class TravelRequestController { public Travel_Request__c newtravelrequest {get;set;} public String recordtype{get;set;} public String AccPC{get;set;} public String CaseOrigin = 'Web'; public TravelRequestController() { newtravelrequest = new Travel_Request__c(); } //Submits the Travel Request public PageReference SubmitTravelRequest() { //Query for the Case record types List<RecordType> rTypes = [SELECT Id FROM RecordType WHERE Name = :recordtype and isActive=true]; if(!rTypes.isEmpty()) { //Id accid; //Decimal decpc = decimal.valueOf(AccPC); newtravelrequest.recordtypeId=rTypes[0].Id; /* ****** CURRENT LOCATION ****** //Current Location List<Account> lcc = [select id, Name, PC__c from Account where PC__c = :decpc]; if (null!=lcc && lcc.size()>0) { accid = lcc[0].id; newtravelrequest.AccountId = accid; } //Sets New Location for drop down menu newtravelrequest.New_Location__c = NewPC; */ try { insert newtravelrequest; // inserts the new travel request into the database newtravelrequest = new Travel_Request__c(); } catch(DmlException ex){ ApexPages.addMessages(ex); } } PageReference travelrequest = new PageReference('/apex/CaseConfirmation'); travelrequest.setRedirect(true); return travelrequest; } }
and here is the visualforce page
<apex:page Controller="TravelRequestController" tabStyle="Account" sidebar="false" showHeader="false"> <apex:sectionHeader title="HHS Receptionists" subtitle="Submit A Travel Request"/> <apex:form id="myForm"> <apex:pageBlock title="Travel Request: Flight and Lodging"> <apex:pageBlockButtons location="bottom"> <!--<apex:commandButton action="{!SubmitTravelRequest}" value="Submit Travel Request" immediate="true"/> --> <apex:actionStatus id="actionstatus"> <apex:facet name="start"> <apex:commandButton value="Processing..." disabled="true" /> </apex:facet> <apex:facet name="stop"> <apex:commandButton id="SubmitButton" action="{!SubmitTravelRequest}" value="Submit Request" status="actionstatus" reRender="myForm"> <apex:param assignTo="{!newtravelrequest.recordtype}" name="rtype" value="Flight_Lodging" id="rtype"/> </apex:commandButton> </apex:facet> </apex:actionStatus> </apex:pageBlockButtons> <apex:messages style="color:#FF0000;"/> <table> <tr> <th>Your Name: </th> <td><apex:inputField required="true" value="{!newtravelrequest.Check_In_Date__c}"/></td> </tr> </table> </apex:pageBlock> </apex:form> </apex:page>
here is the query for the working record type query on the case object
List<RecordType> rTypes = [SELECT Id FROM RecordType WHERE Name = :recordtype and sObjectType='Case' and isActive=true]; if(!rTypes.isEmpty()) { Id accid; Decimal decpc = decimal.valueOf(AccPC); newcase.recordtypeId=rTypes[0].Id;
I tried it with sObjectType='Travel_Request__c but that did not work so I removed it to see if that would resolve it but that made no difference.
Thank you in advance for your help!!