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
EnryEnry 

Visual force page and record type

I'm creating a custom visual force page that allow users to create a new record for a custom object.

I want understand if in the custom VF page i have the standard functionality of the record type:

-see different field according to the visibility of the page layout

-have different picklist values

 

I have found this resource link:

Displaying Record Types

I have tried creating a custom visual force page and two record types.

The record types are linked to different page layout.In one of the two page layouts i have removed some fields.

Pressing the New button i can choose which of the two record types i want.

They open the same VF page,but i can see on my custom vf Page the same fields.

 

I would like to be able to show different fields on my custom VF page according to different record types. Is not possible or is there something that i don't know?

 

Thanks in advantage for any advice.

BR.

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9

You basically have to conditionally render the section of VF page based on recordtype

<apex:pageblock id="pbId">
        <apex:pageblocksection columns="1" id="pbsIs" rendered="{!recordType == 'myRecType1'}">
            <apex:repeat value="{!$ObjectType.My_Object__c.FieldSets.MyFieldSet}" var="f">
                <apex:inputfield value="{!My_Object__c[f]}">
            </apex:inputfield></apex:repeat>
        </apex:pageblocksection>
    </apex:pageblock>

 

have a look at the below condition it basically checks recordtype(a controller variable) if is equal to "myRecType1" then it renders the section. You can multiple checks and sections  with different fieldsets according to your requirement.

 

rendered="{!recordType == 'myRecType1'}"

All Answers

Avidev9Avidev9
You may have to put in your own logic. As far as VF is concerned this will display all the fields that are refered in the page.

You may want to have a look at fieldsets. These can be used with custom logic to show different fields based on recordtype or any conditions.

You can have two fieldsets one for recordtype one and other for recordtype 2, and can use logic in controller to switch them.
EnryEnry

Thanks, looks great!

I have found this resource http://forceguru.blogspot.se/2011/02/using-field-set-on-visual-force-page.html.

I don't understand.

Looking the example i have the logic to show the field set in the vf page, not in the controller.

Please, can you give me other explanation.

Thank again!

Avidev9Avidev9

You basically have to conditionally render the section of VF page based on recordtype

<apex:pageblock id="pbId">
        <apex:pageblocksection columns="1" id="pbsIs" rendered="{!recordType == 'myRecType1'}">
            <apex:repeat value="{!$ObjectType.My_Object__c.FieldSets.MyFieldSet}" var="f">
                <apex:inputfield value="{!My_Object__c[f]}">
            </apex:inputfield></apex:repeat>
        </apex:pageblocksection>
    </apex:pageblock>

 

have a look at the below condition it basically checks recordtype(a controller variable) if is equal to "myRecType1" then it renders the section. You can multiple checks and sections  with different fieldsets according to your requirement.

 

rendered="{!recordType == 'myRecType1'}"
This was selected as the best answer
EnryEnry

Thanks,you are very kind.

In the controller how can access the fields from the field set, I mean which is the syntax?