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
Ewa FrystEwa Fryst 

can anyone help me to create a visualforce page?

I have too many fields on my page layout. i would like to hide some of them depending on the value in a picklist. So i have an object called Business review (based on case) and field Business Outcome with values Pass and Fail. Then I have Pass Reason and Fail reason fields. If business outcome value is Pass i would like to show only Pass reason field and hide Fail reason field. this is only an example but if someone could create a visualforce for me i could then change the values. I would appreciate your help.
 
Best Answer chosen by Ewa Fryst
pconpcon
So for each of these feilds you'll need a method in your controller that returns a Boolean to determin if the field should be rendered.  Then in your page code you'll do a reRender of the other section when you change it.

Controller
global with sharing class MyPage_ControllerExtension {
    private final Id recordId;
    private final Review__c record;
    private final ApexPages.StandardController controller;

    public MyPage_ControllerExtension(ApexPages.StandardController stdController) {
        this.controller = stdController;
        this.recordId = this.controller.getId();

        // Code to get for edit
    }

    private String getOutcome() {
        Review__c review = (Review__c) this.controller.getRecord();
        return review.Outcome__c;
    }

    public Boolean getShowFailReason() {
        return (getOutcome() == 'Fail');
    }

    public Boolean getShowPassReason() {
        return (getOutcome() == 'Pass');
    }

    //Additional code for save and whatnot
}

Visualforce
<apex:page standardController="Review__c" extensions="MyPage_ControllerExtension" title="Review Edit" tabStyle="Review__c">
    <apex:form id="form">
        <apex:pageBlock title="Review Edit">
            <apex:actionRegion>
                <apex:inputField="{!Review__c.Outcome__c}">
                    <apex:actionSupport event="onchange" rerender="reasons" />
                </apex:inputField
            </apex:actionRegion>
            <apex:actionRegion id="reasons">
                <apex:inputField="{!Review__c.FailReason__c}" rendered="{!showFailReason}" />
                <apex:inputField="{!Review__c.PassReason__c}" rendered="{!showPassReason}" />
            </apex:actionRegion>
        </apex:pageBlock>
    </apex:form>
</apex:page>

NOTE: This code has not been tested and may contain typographical or logical errors.

Source: http://blog.deadlypenguin.com/blog/2012/07/09/dynamic-dependent-picklists-in-salesforce/

All Answers

pconpcon
So for each of these feilds you'll need a method in your controller that returns a Boolean to determin if the field should be rendered.  Then in your page code you'll do a reRender of the other section when you change it.

Controller
global with sharing class MyPage_ControllerExtension {
    private final Id recordId;
    private final Review__c record;
    private final ApexPages.StandardController controller;

    public MyPage_ControllerExtension(ApexPages.StandardController stdController) {
        this.controller = stdController;
        this.recordId = this.controller.getId();

        // Code to get for edit
    }

    private String getOutcome() {
        Review__c review = (Review__c) this.controller.getRecord();
        return review.Outcome__c;
    }

    public Boolean getShowFailReason() {
        return (getOutcome() == 'Fail');
    }

    public Boolean getShowPassReason() {
        return (getOutcome() == 'Pass');
    }

    //Additional code for save and whatnot
}

Visualforce
<apex:page standardController="Review__c" extensions="MyPage_ControllerExtension" title="Review Edit" tabStyle="Review__c">
    <apex:form id="form">
        <apex:pageBlock title="Review Edit">
            <apex:actionRegion>
                <apex:inputField="{!Review__c.Outcome__c}">
                    <apex:actionSupport event="onchange" rerender="reasons" />
                </apex:inputField
            </apex:actionRegion>
            <apex:actionRegion id="reasons">
                <apex:inputField="{!Review__c.FailReason__c}" rendered="{!showFailReason}" />
                <apex:inputField="{!Review__c.PassReason__c}" rendered="{!showPassReason}" />
            </apex:actionRegion>
        </apex:pageBlock>
    </apex:form>
</apex:page>

NOTE: This code has not been tested and may contain typographical or logical errors.

Source: http://blog.deadlypenguin.com/blog/2012/07/09/dynamic-dependent-picklists-in-salesforce/
This was selected as the best answer
Ewa FrystEwa Fryst
thank you so much for that. I will try to test it today :-)