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
Tommy GeorgiouTommy Georgiou 

Hide/unhide sections based on the Account type pick list

Hello,

On the account detail we have the account type based on : client, supplier and customer.

When it comes for the supplier we have a section called Supplier with custom fields enabled. The same goes for the rest of the types.
Our problem is that depending on the account type we would like these sections to hide/unhide.

Any suggestions will be helpful.
Thank you in advance.
Best Answer chosen by Tommy Georgiou
Robert ZentgrafRobert Zentgraf
Hi Tommy,

perhaps you can use the account type as a recordtype-field. So, you are able to create different page layouts. And for every recordtype you can assign a different page layout.

Regards
Robert
(mindforce: mind-force.de)

All Answers

MithunPMithunP
Hi Tommy Georgiou,

Here is the sample code, you can create a VF page and test this.
 
<apex:page standardController="Opportunity" extensions="cfs">
<apex:form id="form1">
<apex:pageBlock id="block1">
<apex:outputPanel >
<apex:pageBlockSection id="section1">
<apex:inputField value="{!Opportunity.StageName}" id="populate" >
<apex:actionSupport event="onchange" reRender="section2"/>
</apex:inputField>
</apex:pageBlockSection>

<apex:pageblockSection id="section2" >

<apex:outputPanel rendered="{!IF(Opportunity.StageName == 'Closed Won',true,false)}">
<apex:outputLabel value="Next Step"/>
<apex:inputField value="{!Opportunity.NextStep}" id="textpop" />
</apex:outputPanel>

<apex:outputPanel rendered="{!IF(Opportunity.StageName == 'Prospecting',true,false)}">
<apex:outputLabel value="Amount"/>
<apex:inputField value="{!Opportunity.Amount}"  id="textpop2" />
</apex:outputPanel>

<apex:outputPanel rendered="{!IF(Opportunity.StageName == 'Closed Lost',true,false)}">
<apex:outputLabel value="Type"/>
<apex:inputField value="{!Opportunity.Type}"  id="textpop4" />
</apex:outputPanel>

</apex:pageblockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>

</apex:page>
Best Regards,
Mithun.
 
Robert ZentgrafRobert Zentgraf
Hi Tommy,

perhaps you can use the account type as a recordtype-field. So, you are able to create different page layouts. And for every recordtype you can assign a different page layout.

Regards
Robert
(mindforce: mind-force.de)
This was selected as the best answer
Tommy GeorgiouTommy Georgiou
Thank you Mithun and Robert for your answers. Will try both solutions and come back with the best answer!!
Thank you again
Tommy GeorgiouTommy Georgiou
Mithun,

When I try your sample code I get the error [Error] Error: Apex class 'cfs' does not exist

[Quick Fix] Create Apex class 'public with sharing class cfs'

[Quick Fix] Create Apex class 'public class cfs'

I am really new to SF development part so excuse me for my poor knowledge.
 
Tommy GeorgiouTommy Georgiou
Hi Robert,

It seems to work OK when creating new accounts. The thing though is that I own nearly to 10k accounts with different types. I was thinking with exporting the record ID and import the accounts again that might work
MithunPMithunP
Hi Tommy Georgiou,

Sorry It's my bad, Here is the updated code.
 
<apex:page standardController="Opportunity" >
<apex:form id="form1">
<apex:pageBlock id="block1">
<apex:outputPanel >
<apex:pageBlockSection id="section1">
<apex:inputField value="{!Opportunity.StageName}" id="populate" >
<apex:actionSupport event="onchange" reRender="section2"/>
</apex:inputField>
</apex:pageBlockSection>

<apex:pageblockSection id="section2" >

<apex:outputPanel rendered="{!IF(Opportunity.StageName == 'Closed Won',true,false)}">
<apex:outputLabel value="Next Step"/>
<apex:inputField value="{!Opportunity.NextStep}" id="textpop" />
</apex:outputPanel>

<apex:outputPanel rendered="{!IF(Opportunity.StageName == 'Prospecting',true,false)}">
<apex:outputLabel value="Amount"/>
<apex:inputField value="{!Opportunity.Amount}"  id="textpop2" />
</apex:outputPanel>

<apex:outputPanel rendered="{!IF(Opportunity.StageName == 'Closed Lost',true,false)}">
<apex:outputLabel value="Type"/>
<apex:inputField value="{!Opportunity.Type}"  id="textpop4" />
</apex:outputPanel>

</apex:pageblockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>

</apex:page>
Best Regards,
Mithun.
 
MithunPMithunP
Hi Tommy Georgiou,

​Once you created the VF page change stage picklist values to Prospecting or Closed Won or Closed Lost, so that different sections will appear on your Page.

Best Regards,
Mithun.
Robert RichterRobert Richter
Hi,

I do not think that coding is really necessary here.
In my opinion the best practise for your problem is to use record types.

You can easiely define 3 record types for each account type and then customize the layouts for each record type to hide / unhide sections and fields. By doing so you avoid hard-coding and you have also the possibility to maintain different pickup values lists for each record type. Also you are able to apply changes on the layout in minutes without having to change any visualforce oder apex code.

think about it. If you need any futher help - please let me know.

Best Regards,
Robert



http://www.mind-force.de
Robert ZentgrafRobert Zentgraf
Hi Tommy,

you are right. For the existing accounts you should update the recordtype by upload. You can use e. g. dataloader.io for this to-do.

Regards
Robert
(Mindforce: https://www.mind-force.de)
Tommy GeorgiouTommy Georgiou
Thank you all for your help.

Record types works perfect in this case.
MithunPMithunP
Yes Tommy and Robert, you are right RecordTypes will work for this case.

Best Regards,
Mithun.
Kevin StrangeKevin Strange
Yes, RecordTypes will work - but here's the overhead of that decision - for every record type, you need a page layout, then you need to create workflows, field changes etc... - When a user creates a new record they need to "choose" a record type - record types create a lot of related "maintenance" stuff - plus you have to update mobile layouts as well. Everytime you need to edit a page - you have to do it multiple times and page layouts will eventually "not match". - Mithun's suggestion is much easier maintenance wise.