+ Start a Discussion

Complex Related Lookup Filter

I'm looking for some advice on how to approach a complex "Lookup Filter" that I am unable to create through the normal interface. I'm assuming there may be a way with a VF page or possibly an Apex trigger.


My objects include Order__c and Order_Details__c in a Master/Detail relationship plus Vendor__c and Product__c in a Master/Detail relationship. Vendor_Name__c is a field on the Order__c object defined as Lookup(Vendor__c), and Product_Name__c is a field on the Order_Details__c object defined as Lookup(Product__c).


My challenge is that I need to create a Lookup Filter on Product_Name__c in my Order_Details__c records such that only products for the Vendor_Name__c chosen in the parent Order__c record are displayed.


In other words, a user will first create an Order record and chose the Vendor from whom goods are being purchased. The user will then create one or more Order Detail records (line items) for each Product he wishes to purchase. The list of available Products to purchase should be limited to those offered by the Vendor receiving the Order. Hope this makes sense.


Any techniques, approaches you can offer would be greatly appreciated.


i think it can be done with the lookup filter (havent actually ran a test):


product.vendor equals order.vendor




  1.you can create one more field in Order_Details__c  object Vendor__c 

  2. In the Standard controller you can write like this


Public class NewOrderdsetails


    public Order_Details__c ord{set;get;}

   public NewOrderDetails (ApexPages.StandardController controller)
      ord=(Order_Details__c )controller.getRecord();
      ord.Vendor__c =[select id ,Vendor__c from Order__c   where id=:ord.Order__c ].Vendor__c ;



<style type="text/css">




<apex:outputPanel styleClass="ord" >
<apex:inputfield value="{!Order_Details__c .Vendor__c }" />  --- here i am hiding the vendor in visualforce page


before that you can write the filter criteria


if this is answer for your question plese mark it as Accept as Solution.if not please let me know