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
larrmill59larrmill59 

VForce - Render different page block sections based on record type

I have a page with 5 data entry sections each of which is tied to a specific record type of the object. I would like to only show the one section that applies to the record type that was selected when creating the record. I found the references and code samples for the rendered attribute, but just can't seem to get the syntax correct. The code below is my latest attempt, but it won't save. The error is "Incorrect parameter for operator '='. Expected Object, received Text"

 

<apex:pageBlockSection title="Fee Waiver RME" rendered="{!RME__c.RecordType='012S00000000Pvm'}">

 

Any help would be appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
mulvelingmulveling

"RecordType" is a reference to the associated RecordType object - you should only go through that when you want to access fields on RecordType object (like Name, etc). For the code you've listed here, you'd want to use "RecordTypeId", like this:

 

rendered="{!RME__c.RecordTypeId='012S00000000Pvm'}"

 

HOWEVER, hard-coding Id values like this into Apex/Visualforce code is poor form - for example, it could cause problems if you deploy to a different org (where the equivalent RecordType you wanting to match may have a different id). Often it's a good idea to change such code to something like the following:

 

rendered="{!RME__c.RecordType.Name='MyDesiredRecordTypeNameGoesHere'}"

 

When apps get more complex, you can take the concept a step further and pull out org-specific values/config/logic into CustomSettings tables and/or XML data, which would then be interpreted at runtime by your Apex/Visualforce app.

All Answers

mulvelingmulveling

"RecordType" is a reference to the associated RecordType object - you should only go through that when you want to access fields on RecordType object (like Name, etc). For the code you've listed here, you'd want to use "RecordTypeId", like this:

 

rendered="{!RME__c.RecordTypeId='012S00000000Pvm'}"

 

HOWEVER, hard-coding Id values like this into Apex/Visualforce code is poor form - for example, it could cause problems if you deploy to a different org (where the equivalent RecordType you wanting to match may have a different id). Often it's a good idea to change such code to something like the following:

 

rendered="{!RME__c.RecordType.Name='MyDesiredRecordTypeNameGoesHere'}"

 

When apps get more complex, you can take the concept a step further and pull out org-specific values/config/logic into CustomSettings tables and/or XML data, which would then be interpreted at runtime by your Apex/Visualforce app.

This was selected as the best answer
larrmill59larrmill59

Thanks for the help and the explanation. This works beautifully. I will also implement your suggestion of pulling the recordtype name instead of hard coding the ID prior to moving this to our production org.