1

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?

4
  • No there is not. You might be able to get the Metadata API to work for you.
    – Adrian Larson
    Sep 7, 2017 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, 2017 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, 2017 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, 2017 at 16:50

3 Answers 3

1

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

2

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.

0

As others pointed out, there's currently (as of Spring '21) no supported way to achieve this using native Apex.

On the API front, the Tooling API allows you to get LookupFilter data. Since it's a REST API it is faster and more lightweight than the Metadata API (which is a SOAP API). You'll need elevated permissions to use the Tooling API, but you can set up a Named Credential as an admin for the callouts. There will be a bit of legwork once you get the response, because you need to parse the info and turn it into something you can use in a query (or otherwise for validation purposes), but the info's all there.

LookupFilter Reference: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_lookupfilter.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .