We are implementing a special type of lookup window in a VisualForce page, which displays a set of potential records a user can select from to populate a Lookup value. As a means to allow users to filter potential selections, we wanted to make use the Lookup Filter properties available when configuring a Lookup field.

The only problem is we don't seem to have any way to dynamically access these filter properties through Apex code. The Describe Field Result does not seem to contain this information, and I haven't been able to find anything in the documentation about it.

Is there no way to access Lookup Filter properties from the Apex Schema methods?

  • No there is not. You might be able to get the Metadata API to work for you. – Adrian Larson Sep 7 '17 at 23:17
  • So short of calling out to some external service, it's not possible. That's what I thought. Thanks for the answer! – zeneto Sep 8 '17 at 16:13
  • 1
    If you want to go offroad, you can use a combination of the undocumented and unsupported USING LOOKUP clause with the SOAP API to build this, which might be a little simpler than accessing the metadata. But it's undocumented so YMMV. You can use the SOAP API Describe call to get the filteredLookupInfo for the field, which tells you the controlling fields for the filter. Using this you can create a query over the target object, binding those controlling fields to the query salesforce.stackexchange.com/questions/192280 – James Sep 18 '17 at 20:54
  • Interesting. Seems like what I need, but there must be a reason they stopped supporting it. Also, if I wanted to dynamically BIND which fields need to be factored into the filter, I don't have a way to retrieve those without additional configuration. I'll keep an eye out to see if they bring it back. Good find. – zeneto Sep 20 '17 at 16:50

No there is not. You might be able to get the Metadata API to work for you.

| improve this answer | |

It looks like there is (API 48.0) a new describe method on DescribeFieldResult, getFilteredLookupInfo(). It is not released nor documented though. It returns a FilteredLookupInfo object if you have set up a lookup filter, but sadly the getControllingFields() function always returns an empty list, regardless of the filter setup when I was playing around with it.

However, it still provides you the knowledge whether or not a lookup filter is set, based on which you could do a call using the USING LOOKUP SOQL syntax which is another undocumented and unsupported feature but it might be supported in the future. See also this idea to have its development continued.

Again, not supported, so use it wisely. The officially supported route would probably the Metadata API as @Adrian Larson said.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.