+ Start a Discussion
MRDJMRDJ 

filter records based on a picklist or a lookup field in visual force page

This is the scenario , filter records based on a picklist or a lookup field in visual force page where I am looking for solution.

There is an object objA, it has 4 lookup fields.
Lookup Field1 (LF1) - This field is lookup to ObjB
Lookup Field2 (LF2) - This field is lookup to ObjC
Lookup Field3 (LF3) - This field is lookup to ObjD
Lookup Field4 (LF4) - This field is lookup to ObjE

in the visual force page, all the above lookup fields are dependent on one another. Once LF1 is entered, then LF2 is dependent on LF1 value, LF3 is dependent on LF2 value and LF4 value is dependent on LF3 value

Can someone help me in writing visual force page and apex controller for this scenario
ManjunathManjunath
Hi, 

I have a sample code. Check if this might help.
 
<apex:page standardController="Parent_Object__c" extensions="parentObjectHelper">
    <apex:form >
        <apex:actionStatus id="refreshStat" ><apex:facet name="start" ><img src="/img/loading.gif" /></apex:facet></apex:actionStatus>
        <apex:outputPanel id="panel">
          <apex:inputField value="{!parentObejct.A__c}" >
          <apex:actionSupport event="onchange" status="refreshStat"  reRender="panel" action="{!display}"/>
          </apex:inputField>
          
          <apex:inputField value="{!parentObejct.B__c}" id="bfield"  rendered="{!A}">
          <apex:actionSupport event="onchange" reRender="panel" status="refreshStat" action="{!display}"/>
          </apex:inputField>
          
          <apex:inputField value="{!parentObejct.C__c}" id="cfield" rendered="{!B}"/>
        </apex:outputPanel>
    </apex:form>
</apex:page>
 
public with sharing class parentObjectHelper {
    public Parent_Object__c parentObejct {get;set;}
    public boolean a {get;set;}
    public boolean b {get;set;}
    public boolean c {get;set;}
    public parentObjectHelper(ApexPages.StandardController C){
        parentObejct = new Parent_Object__c ();
    }
    
    public pageReference display(){
        if(parentObejct.A__c!=null){
            System.debug('--------> A');
            a=true;
        }
        if(parentObejct.A__c!=null && parentObejct.B__c!=null){
            System.debug('--------> C');
             a=true;
             b=true;   
        }
        return null;
    }
}

Regards,
Manjunath