You need to sign in to do that
Don't have an account?

How to hide a field in VF page depending upon accessed from objects.
Hi All,
I have created a visualforce page consisting of four fields A, B, C and D.
I'm accessing this page from Accounts and Opportunities.
What I require is :
When i'll access this page from Accounts the field 'C' should become read only and the field 'D' should be Hidden.
But when i'll access this page from Opportunities all the fields should be editable and visible
any help regarding this will be appreciated.
Thanks in Advance.
Hi Uzair,
1) Maintain 2 fields for 'C' i.e. one as <apex:inputText> and other as <apex:outputText>
2) Add rendered property to both the fields of 'C' as well the one for 'D'
e.g.
Controller
public Boolean isAccount {get; set;}
public Boolean isOppty {get; set;}
if( page from Accounts)
{
isAccount = true;
isOppty = false;
}
else
{
isAccount = false;
isOppty = true;
}
Page //launched from Account tab
<apex:inputText value="{!A}" />
<apex:inputText value="{!B}" />
<apex:inputText value="{!C}" rendered="{!isOppty}" /> //will not be rendered since isOppty is false
<apex:outputText value="{!C}" rendered="{!isAccount}" /> //will be rendered since isAccount is true
<apex:inputText value="{!D}" rendered="{!isOppty}" /> //will not be rendered since isOppty is false
Hope this helps.
All Answers
You'd normally achieve this via the rendered attribute of the input field. This attribute can contain a formula for straightforward conditions, or invoke a getter on the controller if more complex logic is required.
when you make properties of field in apex then either you can change display according to your requirement or use rendered property in component by this way:
display:none:// for D field
display:readonly: // for c field in case of account
Hope this helps.
Could you please provide a sample example.
Thanks in advance.
Hi Uzair,
1) Maintain 2 fields for 'C' i.e. one as <apex:inputText> and other as <apex:outputText>
2) Add rendered property to both the fields of 'C' as well the one for 'D'
e.g.
Controller
public Boolean isAccount {get; set;}
public Boolean isOppty {get; set;}
if( page from Accounts)
{
isAccount = true;
isOppty = false;
}
else
{
isAccount = false;
isOppty = true;
}
Page //launched from Account tab
<apex:inputText value="{!A}" />
<apex:inputText value="{!B}" />
<apex:inputText value="{!C}" rendered="{!isOppty}" /> //will not be rendered since isOppty is false
<apex:outputText value="{!C}" rendered="{!isAccount}" /> //will be rendered since isAccount is true
<apex:inputText value="{!D}" rendered="{!isOppty}" /> //will not be rendered since isOppty is false
Hope this helps.
Hi ipsita.biswas,
Thanks for your reply, it worked for me.