+ Start a Discussion

Render Visualforce page based on selected recordtype

I'm overriding standard pagelayout with a visualforce page, but at the same time I'd like to render fields based on the selected recordtype.

I can easily get the recordtype Id by
public string rectypeid {
    return rectypeid;
Is there an easy way to retrieve the RecordtypeName (like above) or am I forced to use a query:
String RTName = [select Name from RecordType where RecordType.SobjectType = 'My_Obj__c' and RecordtypeId =: rectypeid  limit 1][0].Name;
In order to make the code more readable in the future, I'd prefer to use the name string rather than the Id.

Even if I know maintaining the Id is probably easier than the Name.

thanks for any suggestion,

Abu HashimAbu Hashim
Hi Alex,

Yes using Schema object we can retrieve, please go through the below link:

Let me know if you need further info.!!
Ravi Dutt SharmaRavi Dutt Sharma
Hey Alex,

I suggest you not to use the name field. In future, someone might create another record type on same object with same name. In that case your code will not behave as expected. Always use Id instead of name if name is not set to unique.