I have 10 record types. I want to display selected record type name as section header in VF page? how can i show that?
1 Answer
Well if you use the standard controller (with ou without extension, it does not matter) of the Account object, you can do :
<apex:page standardController="Account">
<apex:sectionHeader title="{!Account.RecordType.Name}" subtitle="{!Account.Name}" rendered="{!NOT(ISBLANK(Account.RecordTypeId))}" />
</apex:page>
If you use a custom controller :
public class myTest {
public Account a { get; set; }
public myTest() {
Id theId = ApexPages.currentPage().getParameters().get('id');
a = [SELECT Id, Name, RecordTypeId, RecordType.Name FROM Account WHERE Id =: theId];
}
}
<apex:page controller="myTest" >
<apex:sectionHeader title="{!a.RecordType.Name}" subtitle="{!a.Name}" rendered="{!NOT(ISBLANK(a.RecordTypeId))}" />
</apex:page>
I know the code is completely dirty but you get the idea ;)
The rendered
tag is useful if the Account does not have a record type (it can happen when you create record types when accounts already exist for instance), so you avoid yourself a "Attempt to dereference a null object" error thrown at you face haha