+ Start a Discussion
Mike ArthurMike Arthur 

Filtered lookup field on Visualforce page returns no values

I have a Visualforce page for creating Opportunity Line Item (OLI) records.  I have a custom OLI field 'Against__c'.  It is a lookup to a custom object 'Account_Course__c'.

Account_Course__c has a custom field Account__c which is a lookup to Account.

I want the OLI Against__c lookup to be filtered so that only Account_Course__c records with the same Account as the Opp of the OLI are returned.

Since I cannot span the relationship to Opportunity in the Against__c lookup filter I have another custom field Account__c on OLI, also a lookup to Account.  I populate this with the Opp Account when the page is rendered.

When I create an OLI record, the 'Account' field is pre-filled correctly but 'Against' lookup returns no rows (when there are valid values available).  If I then edit the newly created OLI record, Account is populated correctly and the Against lookup now shows the correct valid values.

In the online help for examples of filtered lookups it gives the example of a filter on Case lookup to Contact so that only Contacts with the same Account as the Case are returned.  My example has a similar data model structure, except I'm using a VF page.

The problem is the same as the one described here - https://help.salesforce.com/articleView?id=000239898&type=1 - but OLI to Account and Account Course to Account are both lookups.  No master detail.

What is also similar to the above is that if I type in the name of a valid 'Against' record when creating an OLI record, it saves correctly.

Any ideas?