---
schema_version: "1"
id: 9f7a46df18cf80dc0947ff7f1ef5803025a11bb9d5afea6d28c53b77d8fd5755
title: Filters in the Apex Connector Framework
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_connector_filters.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connector_filters.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7c4e62ac90436dd1e82e90d645ce9782294339f05d41e5684a574c5376948276
description: The DataSource.QueryContext contains one DataSource.TableSelection. The DataSource.SearchContext can have more than one TableSelection. Each TableSelection has a filter property that represents the WHERE clause in a SOQL or SOSL query.
---
# Filters in the Apex Connector Framework

The DataSource.QueryContext contains one DataSource.TableSelection. The DataSource.SearchContext can have more than one TableSelection. Each TableSelection has a filter property that represents the WHERE clause in a SOQL or SOSL query.

For example, when a user goes to an external object’s record detail page, your DataSource.Connection is executed. Behind the scenes, we generate a SOQL query similar to the following. In this query, columnNames, externalObjectApiName, and selectedExternalObjectExternalId are placeholder values.

SELECT columnNames 
FROM externalObjectApiName 
WHERE ExternalId = 'selectedExternalObjectExternalId'

This SOQL query causes the query method on your DataSource.Connection class to be invoked. The following code can detect this condition.

if (context.tableSelection.filter != null) {
    if (context.tableSelection.filter.type == DataSource.FilterType.EQUALS 
        && 'ExternalId' ==  context.tableSelection.filter.columnName 
        && context.tableSelection.filter.columnValue instanceOf String) {
        String selection = (String)context.tableSelection.filter.columnValue;
        return DataSource.TableResult.get(true, null, 
                tableSelection.tableSelected, findSingleResult(selection));
    }
}

This code example assumes that you implemented a findSingleResult method that returns a single record, given the selected ExternalId. Make sure that your code obtains the record that matches the requested ExternalId.

- **[Evaluating Filters in the Apex Connector Framework](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connector_filters_evaluating.htm)**  
    A filter evaluates to true for a row if that row matches the conditions that the filter describes.
- **[Compound Filters in the Apex Connector Framework](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connector_filters_compound.htm)**  
    Filters can have child filters, which are stored in the subfilters property.