---
schema_version: "1"
id: d726bcdf458659377dca27aa2c8688764db0c7c32c651a0833fbd6fd11df33a0
title: QueryContext Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_DataSource_QueryContext.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_QueryContext.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: efd7fa6b1b4003bc8d75ed0cf14234baa36ae309c9880d49d306d538de5fb85a
description: An instance of QueryContext is provided to the query method on your DataSource.Connection class. The instance corresponds to a SOQL request.Query token that’s used for server-driven paging to determine and fetch the subsequent batch of results.Query details that represent the FROM, ORDER BY, SELECT, and WHERE clauses in a SOQL or SOSL query.Creates an instance of the QueryContext class.
---
# QueryContext Class

An instance of QueryContext is provided to the [query](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_Connection.htm#apex_DataSource_Connection_query "Invoked by a SOQL query of an external object. A SOQL query is generated and executed when a user visits an external object’s list view or record detail page in Salesforce. Returns the results of the query.") method on your [DataSource.Connection](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_Connection.htm#apex_class_DataSource_Connection "Extend this class to enable your Salesforce org to sync the external system’s schema and to handle queries, searches, and write operations (upsert and delete) of the external data. This class extends the DataSourceUtil class and inherits its methods.") class. The instance corresponds to a SOQL request.

## Namespace

[DataSource](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_DataSource.htm "The DataSource namespace provides the classes for the Apex Connector Framework. Use the Apex Connector Framework to develop a custom adapter for Salesforce Connect. Then connect your Salesforce organization to any data anywhere via the Salesforce Connect custom adapter.")

- **[QueryContext Properties](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_QueryContext.htm#apex_DataSource_QueryContext_properties)**
- **[QueryContext Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_QueryContext.htm#apex_DataSource_QueryContext_methods)**

## QueryContext Properties

The following are properties for QueryContext.

- **[queryMoreToken](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_QueryContext.htm#apex_DataSource_QueryContext_queryMoreToken)**  
    Query token that’s used for server-driven paging to determine and fetch the subsequent batch of results.
- **[tableSelection](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_QueryContext.htm#apex_DataSource_QueryContext_tableSelection)**  
    Query details that represent the FROM, ORDER BY, SELECT, and WHERE clauses in a SOQL or SOSL query.

### queryMoreToken

Query token that’s used for server-driven paging to determine and fetch the subsequent batch of results.

#### Signature

public String queryMoreToken {get; set;}

#### Property Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

### tableSelection

Query details that represent the FROM, ORDER BY, SELECT, and WHERE clauses in a SOQL or SOSL query.

#### Signature

public DataSource.TableSelection tableSelection {get; set;}

#### Property Value

Type: [DataSource.TableSelection](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_TableSelection.htm#apex_class_DataSource_TableSelection "Contains a breakdown of the SOQL or SOSL query. Its properties represent the FROM, ORDER BY, SELECT, and WHERE clauses in the query.")

## QueryContext Methods

The following are methods for QueryContext.

- **[get(metadata, offset, maxResults, tableSelection)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_QueryContext.htm#apex_DataSource_QueryContext_get)**  
    Creates an instance of the [QueryContext](#apex_class_DataSource_QueryContext "An instance of QueryContext is provided to the query method on your DataSource.Connection class. The instance corresponds to a SOQL request.") class.

### get(metadata, offset, maxResults, tableSelection)

Creates an instance of the [QueryContext](#apex_class_DataSource_QueryContext "An instance of QueryContext is provided to the query method on your DataSource.Connection class. The instance corresponds to a SOQL request.") class.

#### Signature

public static DataSource.QueryContext get(List<DataSource.Table> metadata, Integer offset, Integer maxResults, DataSource.TableSelection tableSelection)

#### Parameters

- **metadata**:
    
    Type: List<[DataSource.Table](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_Table.htm#apex_class_DataSource_Table "Describes a table on an external system that the Salesforce Connect custom adapter connects to. This class extends the DataSourceUtil class and inherits its methods.")\>
    
    List of table metadata that describes the external system’s tables to query.
- **offset**:
    
    Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")
    
    Used
    
    for client-driven paging. Specifies the starting row offset into the query’s result set.
- **maxResults**:
    
    Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")
    
    Used
    
    for client-driven paging. Specifies the maximum number of rows to return in each batch.
- **tableSelection**:
    
    Type: [DataSource.TableSelection](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_TableSelection.htm#apex_class_DataSource_TableSelection "Contains a breakdown of the SOQL or SOSL query. Its properties represent the FROM, ORDER BY, SELECT, and WHERE clauses in the query.")
    
    Query details that represent
    
    the FROM, ORDER BY, SELECT, and WHERE clauses in a SOQL or SOSL query.

#### Return Value

Type: [DataSource.QueryContext](#apex_class_DataSource_QueryContext "An instance of QueryContext is provided to the query method on your DataSource.Connection class. The instance corresponds to a SOQL request.")