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
Shane QuiringShane Quiring 

Reference the record type field in a visualforce page

Hello Experts,

I am new to APEX coding and Visualforce Pages, but learning. I am having a bit of an issue with a VF page. I am trying to refrence either the record type ID or the record type name in an "IF" statement. Here is what I am trying to do, if the record type id equals a certain ID then show "Supplier Contract" else "Client Contract". I am of course running into an error. Here is the error and the coding:

Error: "Error: Unknown property 'ServiceContractStandardController.RecordType'"

Coding:
<apex:page standardController="ServiceContract" showHeader="true" 
        tabStyle="servicecontract" >
        <center>
        <apex:outputPanel style="background-color:red;width:100%;padding:20px;" 
    rendered="{!IF(RecordType.Id=='012K00000008w7q',h1,h2)}">
       <style>
h1 {
    font-size: 20px;
}
</style> 
        <h1>SUPPLIER ACCOUNT</h1>
        <style>
h2 {
    font-size: 20px;
}
</style>
        <h2>CLIENT CONTRACT</h2>
       </apex:outputPanel>
    </center>
        <style>
      .activeTab {background-color: #236FBD; color:white; 
         background-image:none}
      .inactiveTab { background-color: lightgrey; color:black; 
         background-image:none}
   </style>
   <apex:tabPanel switchType="client" selectedTab="tabdetails" 
                  id="ServiceAccountTabPanel" tabClass="activeTab" 
                  inactiveTabClass="inactiveTab">   
      <apex:tab label="Details" name="ServiceAcctDetails" id="tabdetails">
         <apex:detail relatedList="false" title="true"/>
      </apex:tab>
      <apex:tab label="Approval History" name="ApprovalHistory"
                 id="tabApprovalHist">
          <apex:relatedList subject="{!servicecontract}"
                          list="ProcessSteps" />
      </apex:tab>
            <apex:tab label="Notes and Attachments" name="NotesAndAttachments"
                 id="tabNotesAndAttachments">
          <apex:relatedList subject="{!servicecontract}"
                          list="CombinedAttachments" />
      </apex:tab>
            <apex:tab label="Field History" name="FieldHistory" 
                id="fieldhistory">
<apex:outputLink value="https://cs9.salesforce.com/_ui/common/history/ui/EntityHistoryFilterPage?id={!servicecontract.id}">
click to view field history
</apex:outputLink>
</apex:tab>
      </apex:tabPanel>
</apex:page>

Any Assistance would greatly apprecitated, thank-you. 

v/r
Shane
Best Answer chosen by Shane Quiring
Shane QuiringShane Quiring
Hi Balaji,

I was able to resolve this another way by creating a formula field (IF Statement) that references the record type id and brings back either "Supplier Contract" or "Client Contract". Here is the coding that I used:

<center>
        <apex:outputPanel style="background-color:red;width:100%;padding:20px;" 
    rendered="{!ServiceContract.Record_Type_Name__c=='Client Contract'}">
    <style>
h1 {
    font-size: 20px;
}
</style> 
        <h1>CLIENT CONTRACT!</h1>
    </apex:outputPanel>
    </center>
    <center>
        <apex:outputPanel style="background-color:red;width:100%;padding:20px;" 
    rendered="{!ServiceContract.Record_Type_Name__c=='Supplier Contract'}">
    <style>
h2 {
    font-size: 20px;
}
</style> 
        <h2>SUPPLIER CONTRACT!</h2>
    </apex:outputPanel>

Unfortunately at this time I am not very versed is APEX Triggers or Classes and I was unable to write the Class.

Thank-you for the assistance and actually pointing me another direction.

v/r
Shane

All Answers

Balaji BondarBalaji Bondar
Hi Shane,

Create a property in the controller and assign the record type id , refer the RecordTypeIdString on VF page.
public string RecordTypeIdString { set;get; }
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
Shane QuiringShane Quiring
Hi Balaji,

Thank-you for your assistance, just make sure that I am clear, I will need to create a controller, as discussed in the following link: https://www.salesforce.com/us/developer/docs/pages/Content/pages_dynamic_vf_globals_objecttype.htm  Is this correct?

v/r
Shane
Shane QuiringShane Quiring
Hi Balaji,

I was able to resolve this another way by creating a formula field (IF Statement) that references the record type id and brings back either "Supplier Contract" or "Client Contract". Here is the coding that I used:

<center>
        <apex:outputPanel style="background-color:red;width:100%;padding:20px;" 
    rendered="{!ServiceContract.Record_Type_Name__c=='Client Contract'}">
    <style>
h1 {
    font-size: 20px;
}
</style> 
        <h1>CLIENT CONTRACT!</h1>
    </apex:outputPanel>
    </center>
    <center>
        <apex:outputPanel style="background-color:red;width:100%;padding:20px;" 
    rendered="{!ServiceContract.Record_Type_Name__c=='Supplier Contract'}">
    <style>
h2 {
    font-size: 20px;
}
</style> 
        <h2>SUPPLIER CONTRACT!</h2>
    </apex:outputPanel>

Unfortunately at this time I am not very versed is APEX Triggers or Classes and I was unable to write the Class.

Thank-you for the assistance and actually pointing me another direction.

v/r
Shane
This was selected as the best answer