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
Andrea SloanAndrea Sloan 

Show Hide Field

I have a picklist field called Account Category which I would like to make invisible on my pae layout under the scenario when user selcts the following to picklist fields with the show values

Account classification field = retail
Source market field = USA

Only once they have selected values for those two fields must the account category field appear on my screen under accoutns screen provided the populated values are not the ones above. I don't know any JAVA but I'm guessing this might be able to be done with JAVA? Can someone help me with the appropriate coding?

thank you
Best Answer chosen by Andrea Sloan
GauravGargGauravGarg

Hi Andrea,

If we can manage user in different profile so that only limited user groups can access this field. Or you can try using permission sets, if users from same profile need different access on same field.

Hope this will solve your problem, please select as best if your problem resolve, else let me know if you more insight on this. 

Thanks,

Gaurav

All Answers

GauravGargGauravGarg
Hi Andrea,

Are we using custom VF page or standard page.
  • If it is custom VF page, we can "rendered" action which will check for above condition and display field accordingly.
  • Currently we cannot implement above feature on standard page.

Below link might helps you understanding how we can hide/show field on VF page:
https://developer.salesforce.com/forums/?id=906F000000098ZjIAI

Hope this will solve your problem, please let me know if you need more insight on this. 

Thanks,

Gaurav
Email: gauravgarg.nmims@gmail.com

Andrea SloanAndrea Sloan
Hi Gaurav:

I'm not familiar too much with the techinical aspect of Visual Force. What is a Custom VisualForce page as opposed to a standard page?
Andrea SloanAndrea Sloan
I want this to work on the Accounts screen. one field is to be visible subject that a give value appears on one of my picklist fields and another value in a second picklist field.

If My Accounts Classification picklist value is equal to "Retail" and my Source Market field equals either"USA" or "Canada" then my Account Category field should not appear in my Account's page layout.

How would I write this? I do need to see this field on the page for all other account record combinations. On the main account page as well as in Edit mode to be clear.

thanks!
Vasani ParthVasani Parth
Andrea,

You can try this working code,
<apex:page standardController="Campaign" showHeader="true" >
	<apex:form>
		<apex:outputPanel id="t1">
			<apex:pageBlock>
				<apex:pageBlockSection columns="2" title="Information">
					<apex:inputField value="{!Campaign.Name}" />
					<apex:inputField value="{!Campaign.StartDate}" />
					<apex:inputField value="{!Campaign.Status}" />
					<apex:inputField value="{!Campaign.Type}" />
					<apex:inputField value="{!Campaign.Primary_Campaign_Attribute__c}"> 
						<apex:actionSupport event="onchange" rerender="t1" />
					</apex:inputField>
				</apex:pageBlockSection>
				<apex:pageBlockSection columns="1" title="Primary Campaign">
					<apex:inputField value="{!Campaign.Primary_Campaign_Attribute_Religion__c}" rendered="{!IF( Campaign.Primary_Campaign_Attribute__c == 'Religious Affiliation', true, false )}" >
						<apex:actionSupport event="onchange" rerender="t1" />
					</apex:inputField>
					<apex:inputField value="{!Campaign.Primary_Campaign_Attribute_Christianity__c}" rendered="{!IF( Campaign.Primary_Campaign_Attribute_Religion__c == 'Christian', true, false )}" />
				</apex:pageBlockSection>
			</apex:pageBlock> 
		</apex:outputPanel>
	</apex:form>
</apex:page>

You can change your fields accordingly. 

Please mark this as the best answer if this helps
GauravGargGauravGarg
Hi Andrea,

Thanks for providing the proper details on the requriement.
First of all standard vf custom page
Standard pages are the one which will be handled by Salesforce team i.e. the Look, behaviour will be taken care by Standard Salesforce team and we can just add remove sections / fields / related list on the pages. 
Custom Pages, we implement Custom pages basically known as VF pages. This will be build on Salesforce website only but we can customize using Javascript, Ajax, Jquery and many other web technologies.

According to your requirement hide / show of fields based on paritcular conditions, we need to go for Custom Page approach. 

Please let me know when can we start working on this. 

Thanks,
Gaurav
Andrea SloanAndrea Sloan
Hi Guarav:

So therefore the code you provided abovce would not work for the Accounts screen? I've already started working on this which was why I was looking if anyone had any particular coding I can put into a VisualForce customized page. I have a feeling this may work with Java script except I don't know how to write Java.

Can you help me? Would you know the correct code I would need on the Customized VisualForce page? Do I also need , Apex?
Any coding you could provide with the nameso of the fields I wrote above would be greatly appreciated!!!

Thank youvery much in advance for your help!

Andrea
 
GauravGargGauravGarg
Hi Andrea,

Please try below sample code for you help:

Visualforce sample page:
<apex: page standardController="Account" extension="customAccountController" id="pg">
	<apex:form id="frm">
		<apex:pageblock id="pb"> 
			<apex:pageBlockSection id="pbs" columns="2" title="Information">
				<apex:inputField value="{!theAccount.Accounts_Classification__c}"/>
				<apex:inputField value="{!theAccount.Source_Market__c}"/>
				<apex:inputField value="{!theAccount.Account_Category__c}" rendered="{!!isVisible}"/>
			</apex:pageBlockSection>
		</apex:pageblock>
	</apex:form>
</apex: page>

Controller to above VF page:
public with sharing class customAccountController {
	public Case theAccount {get;set;}
    public boolean isVisible{get;set;}
	
	public customAccountController(ApexPages.StandardController stdcontroller) {
		isVisible = false;
		String AccountId = ApexPages.currentPage().getParameters().get('id');
		if(AccountId != null){
			 Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();
			 theAccount = (Account) stdController.getRecord();
			 if(theAccount != null){
				if(theAccount.Accounts_Classification__c == 'retail' && (theAccount.Source_Market__c == 'USA' || theAccount.Source_Market__c == 'Canada'))
					isVisible = true;
			 }
		}
	}
}


Let me know if you need more assistance on this.

Thanks,

Gaurav

Andrea SloanAndrea Sloan
Hi Gaurav: Thank you for this. I will try it out and let you know on Monday as I'm not in the office today. Question: Can you tweak this code for me so that the field is also invisible under the following scenarios: Source Market field contains any given value that is NOT Mexico or Brazil regardless of what the values contained in the Account Classification field are? That is in addition to the first statement you had already inserted. I need the field to be invisible on the regular account page but ALSO to be invisible when the user begins to enter the edit mode of account and become visible if the logic is fulfilled after the source market field and Account Classification fields are entered. Will the Visual Force do this?(start off by being invisible to users) Thank you!!!
GauravGargGauravGarg

Hi Andrea,

Please once try above logic, if that works as per the requirement. Further we can tweak the code with whatever requirement we have. 

Thanks,

Gaurav

Andrea SloanAndrea Sloan
Hi Guarav:

I have copy pasted your code both for visual Force page and Apex/Controller and I'm getting the errors in my screenshot. The only change I made was that I remove the "s" you had put in for my Account Classification field as the field doesn't contain an "s". Please see my errors below.


User-added image



User-added image


 
GauravGargGauravGarg
Hi Andrea,

I have update some code, please try now.
 
Visual Force:
<apex:page standardController="Account" extension="customAccountController" id="pg">
	<apex:form id="frm">
		<apex:pageblock id="pb"> 
			<apex:pageBlockSection id="pbs" columns="2" title="Information">
				<apex:inputField value="{!theAccount.Accounts_Classification__c}"/>
				<apex:inputField value="{!theAccount.Source_Market__c}"/>
				<apex:inputField value="{!theAccount.Account_Category__c}" rendered="{!!isVisible}"/>
			</apex:pageBlockSection>
		</apex:pageblock>
	</apex:form>
</apex: page>
 
Controller

public with sharing class customAccountController {
	public Account theAccount {get;set;}
    public boolean isVisible{get;set;}
	
	public customAccountController(ApexPages.StandardController stdcontroller) {
		isVisible = false;
		String AccountId = ApexPages.currentPage().getParameters().get('id');
		if(AccountId != null){
			 Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();
			 theAccount = (Account) stdController.getRecord();
			 if(theAccount != null){
				if(theAccount.Accounts_Classification__c == 'retail' && (theAccount.Source_Market__c == 'USA' || theAccount.Source_Market__c == 'Canada'))
					isVisible = true;
			 }
		}
	}
}


Also, I have accepted you request in skype. If possbile, please response on the same. 

Thanks,

Gaurav

Andrea SloanAndrea Sloan
Hi  Gaurav:

Thank you for this and for accepting the Skype request. The Apex part is now good but I'm now getting the following error on the VisualForce page. Please note when you send back that my field is call Account_Classification__c which does not include an "s" on the word Account per my screenshot.
User-added image
 
GauravGargGauravGarg
Hi Andrea,

Great, apex worked. Please note updated vf page code. Hope this will also work for you. 
 
<apex:page standardController="Account" extensions="customAccountController" id="pg">
	<apex:form id="frm">
		<apex:pageblock id="pb"> 
			<apex:pageBlockSection id="pbs" columns="2" title="Information">
				<apex:inputField value="{!theAccount.Account_Classification__c}"/>
				<apex:inputField value="{!theAccount.Source_Market__c}"/>
				<apex:inputField value="{!theAccount.Account_Category__c}" rendered="{!!isVisible}"/>
			</apex:pageBlockSection>
		</apex:pageblock>
	</apex:form>
</apex:page>

Thanks,
Gaurav
GauravGargGauravGarg

Hi Andrea,

If we can manage user in different profile so that only limited user groups can access this field. Or you can try using permission sets, if users from same profile need different access on same field.

Hope this will solve your problem, please select as best if your problem resolve, else let me know if you more insight on this. 

Thanks,

Gaurav

This was selected as the best answer
Andrea SloanAndrea Sloan
Yes, this will be the best of all solutions for now since a VisualForce page will not hide the field under the Account Detail save mode. it's too bad that fields cannot be hidden under standard page layouts!

thank you for your help!
GauravGargGauravGarg
welcome Andrea.