You need to sign in to do that
Don't have an account?
elpaso750
Render Visualforce page based on selected recordtype
Hi,
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
Even if I know maintaining the Id is probably easier than the Name.
thanks for any suggestion,
Alex
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 { get { rectypeid=ApexPages.currentPage().getParameters().get('RecordType'); return rectypeid; } set; }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,
Alex
Yes using Schema object we can retrieve, please go through the below link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Schema_RecordTypeInfo.htm
Let me know if you need further info.!!
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.