You can try using the tooling API and implementing the API in apex to achieve the same.
Check the details of the API here
https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_lookupfilter.htm
Here is the draft code to get you started, Note the below
- It's not production-ready code.
- Add Error Handling and Unit Tests
- LWC Code is not shown and I focus on only backend code
- I have simplified authentication using vf page. I recommend you look into Connected Apps and Named Credential to make sure you are securely authenticating.
Here we go with detailed code
Create a VF page to get you the session, since with LWC Session we do not allow you to access the Tooling API
<apex:page contentType="application/json">
{!$Api.Session_ID}
</apex:page>
Create a Class to read SessionID from vf and expose as Utility to other apex class
public inherited sharing class SessionHelper {
public static String getSessionId() {
return Test.isRunningTest()
? ''
: Page.session.getContent().toString().trim();
}
}
Create an API client to make outbound apex HTTP callout
public inherited sharing class APIClient {
public static String makeAPICall(String endPoint, String method) {
try {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setHeader(
'Authorization',
'Bearer ' + SessionHelper.getSessionId()
);
request.setTimeout(60000);
request.setEndpoint(endPoint);
request.setMethod(method);
HttpResponse response = http.send(request);
return response.getBody();
} catch (Exception ex) {
system.debug('Exception in tooling API Call:' + ex.getMessage());
return ex.getMessage();
}
}
}
Create an apex class to fetch the LookupFilter Metadata
public with sharing class LookupFilterController {
static String toolingSOQL(string queryString) {
Double apiVersion = getApiVersion();
String path = '/tooling/query/?q=' + queryString.replace(' ', '+');
String endpointurl =
Url.getOrgDomainUrl().toExternalForm() +
'/services/data/v' +
apiVersion +
path;
return APIClient.makeAPICall(endpointurl, 'GET');
}
static Double getApiVersion() {
return [
SELECT ApiVersion
FROM ApexClass
ORDER BY ApiVersion DESC
LIMIT 1
]
.ApiVersion;
}
@AuraEnabled(cacheable=true)
public static string getLookupFilters(String developerName) {
string toolingsoql =
'SELECT FullName,' +
'DeveloperName,' +
'SourceObject,' +
'Metadata'
'FROM LookupFilter ' +
'WHERE DeveloperName=\'' +
developerName +
'\'';
return toolingSOQL(toolingsoql);
}
}
I have not thoroughly tested the above code but I am hoping it unblocks you!