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
Amrin.Amrin. 

How to show and hide lookup field based on different objects using visualforce page?

Hi,

Currently I have 4 objects A,B,C and D these are the parent object for Object O.  So when I come from record A, on object O page layout i want to display only A's lookup field and hide rest 3  lookup fields B,C, D.

Similarly when I come from record B, on O's page layout I want to display B's lookup field and hide 3 rest lookup fields A,C, D.

And so on for remaining 2 objects..

 

I know this can be achieved through record type, but in my requirement they dont want to achieve it through standard record type so I want to use Visualforce page to avoid record type selection menu.

 

I have done some initial hands on but not getting up to the mark... please help!!!!

 

NOTE:I have replaced Fund, CDE, Allocatee and Project with A, B, C and D and program with O.

 

<apex:page standardController="program__c" extensions="Program_Ext" id="pagecamt">
<apex:form id="frmCmpt">

<apex:pageBlock tabStyle="program__c" >
<apex:pageBlockButtons >

<apex:commandButton action="{!save}" value="Save" />
<apex:commandButton action="{!Cancel}" value="Cancel" />

</apex:pageBlockButtons>



<apex:pageBlockSection title="Information" columns="1">

<apex:inputField value="{!program__c.Name}" id="inputTypeField" required="true" />

<apex:inputField value="{!program__c.Fund__c}" id="form2" rendered="{!showlen}" />
<apex:inputField value="{!program__c.CDE__c}" id="form3" rendered="{!showlen1}" />
<apex:inputField value="{!program__c.Allocatee__c}" id="form4" rendered="{showlen2}" />
<apex:inputField value="{!program__c.Project__c}" id="form5" rendered="{!showlen3}"/>


</apex:pageBlockSection>



</apex:pageBlock>
</apex:form>
</apex:page>

 

CONTROLLER

 

public class Program_Ext {

public Program_Ext(ApexPages.StandardController controller) {

}


public Boolean showLen {
get {
if (program__c.Fund__c!= null && program__c.CDE__c == null && program__c.Allocatee__c== null && program__c.Project== null ) {
return true;
} else {
return false;
}
}
set;}

public Boolean showLen1 {
get {
if ( program__c.CDE__c != null && program__c.Fund__c == null && program__c.Allocatee__c  == null &&  program__c. Project__c == null) {
return false;
} else {
return true;
}
}
set;}

 

 public Boolean showLen2 {
get {
if ( program__c.Allocatee__c != null && program__c.CDE__c == null && program__c.Fund__c == null &&  program__c. Project__c == null) {
return false;
} else {
return true;
}

set;}

 

public Boolean showLen1 {
get {
if ( program__c.CDE__c == null && program__c.Fund__c == null && program__c.Allocatee__c ==null && program__c. Project__c != null) {
return false;
} else {
return true;
}

set;}

}

 

 

its still showing all the lookup fields on Vf and not hiding any.. please help

 

PremanathPremanath

as per understood your code

 

On pageload it giving true

so write a constructor for that class

 

public class Program_Ext {

public Program_Ext(ApexPages.StandardController controller) {

   showlen=false;

showlen1=false;

showlen2=false;

showlen3=false;

}

 

Then you can follow up with your code..

 

Stil if you didn't get your requirement...

 

use System.Debug();

For every step and go through it..

 

 

 

If It is helpful plz make it as solution for others it may benfit


Prem