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
Collen Mayer 6Collen Mayer 6 

Pass Recordtype ID from Visualforce page

Hi All,
I have a custom object called Satisfaction Surveys.  I will have multiple visualforce pages that allow the user to fill out a satisfaction survey of a given record type depending on the service they receieved.  I have the following controller that works well, but I would like to pass it a recordtype id from the visualforce page.  How would i do that?  Record type 1 would be survey for service 1 and Record type 2 would be a different survey for service 2. Visualforce page 1 would create a survey of record type 1 and visual force page 2 would create a survey of record type 2.  I assume I could do this all with the single controller:
 
public with sharing class CreateSatisfactionSurvey {

  // the contact record you are adding values to
  public 	Satisfaction_Surveys__c survey {
    get {
      if (survey == null)
        survey = new Satisfaction_Surveys__c ();
      return survey;
    }
    set;
  }

  public CreateSatisfactionSurvey() {
    // blank constructor
  }

  // save button is clicked
  public PageReference save() {

    try {
      insert survey; // inserts the new record into the database
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new survey.'));
      return null;
    }

    // if successfully inserted new survey, then displays the thank you page.
    return Page.Survey_Create_Thankyou;
  }

}

A sample visualforce page (which I would like to modify based on survey type/record type) is:
 
<apex:page Controller="CreateSatisfactionSurvey">  
  <apex:sectionHeader title="Satisfaction Survey" subtitle="Please rate the service you receieved."/>

  <apex:form >
    <apex:pageMessages /> <!-- this is where the error messages will appear -->
    <apex:pageBlock title="Survey Response">

      <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
      </apex:pageBlockButtons>

      <apex:pageBlockSection showHeader="false" columns="2">
      	<apex:inputField value="{!survey.Program__c}" />  
          <apex:inputField value="{!survey.Access_Comm_Resources__c}" />
      </apex:pageBlockSection>

    </apex:pageBlock>
  </apex:form>
</apex:page>

Thanks,
Collen