---
schema_version: "1"
id: 2b7c9c4a7007d1327b82cce3894d50cab581d97de6010650c50715a37ea5f70c
title: SearchContext Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_DataSource_SearchContext.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_SearchContext.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: e2b8ab752eded34d58f81c91a3558d81e702db83c4cdb468674db3eb054a851c
description: An instance of SearchContext is provided to the search method on your DataSource.Connection class. The instance corresponds to a search or SOSL request.Creates an instance of the SearchContext class with the specified parameter values.Creates an instance of the SearchContext class.The user-entered search string as a case-sensitive single phrase, with all non-alphanumeric characters removed.List of queries and their details. The details represent the FROM, ORDER BY, SELECT, and WHERE clauses in each SOQL or SOSL query.
---
# SearchContext Class

An instance of SearchContext is provided to the [search](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_Connection.htm#apex_DataSource_Connection_search "Invoked by a SOSL query of an external object or when a user performs a Salesforce global search that also searches external objects. 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 search or SOSL 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.")

- **[SearchContext Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_SearchContext.htm#apex_DataSource_SearchContext_constructors)**
- **[SearchContext Properties](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_SearchContext.htm#apex_DataSource_SearchContext_properties)**

## SearchContext Constructors

The following are constructors for SearchContext.

- **[SearchContext(metadata, offset, maxResults, tableSelections, searchPhrase)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_SearchContext.htm#apex_DataSource_SearchContext_ctor)**  
    Creates an instance of the [SearchContext](#apex_class_DataSource_SearchContext "An instance of SearchContext is provided to the search method on your DataSource.Connection class. The instance corresponds to a search or SOSL request.") class with the specified parameter values.
- **[SearchContext()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_SearchContext.htm#apex_DataSource_SearchContext_ctor_2)**  
    Creates an instance of the [SearchContext](#apex_class_DataSource_SearchContext "An instance of SearchContext is provided to the search method on your DataSource.Connection class. The instance corresponds to a search or SOSL request.") class.

### SearchContext(metadata, offset, maxResults, tableSelections, searchPhrase)

Creates an instance of the [SearchContext](#apex_class_DataSource_SearchContext "An instance of SearchContext is provided to the search method on your DataSource.Connection class. The instance corresponds to a search or SOSL request.") class with the specified parameter values.

#### Signature

public SearchContext(List<DataSource.Table> metadata, Integer offset, Integer maxResults, List<DataSource.TableSelection> tableSelections, String searchPhrase)

#### 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.")
    
    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.")
    
    Specifies the maximum number of rows to return in each batch.
- **tableSelections**:
    
    Type: List<[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.")\>
    
    List of queries and their details. The details represent the FROM, ORDER BY, SELECT, and WHERE clauses in each SOQL or SOSL query.
- **searchPhrase**:
    
    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.")
    
    The user-entered search string as a case-sensitive single phrase, with all non-alphanumeric characters removed.

### SearchContext()

Creates an instance of the [SearchContext](#apex_class_DataSource_SearchContext "An instance of SearchContext is provided to the search method on your DataSource.Connection class. The instance corresponds to a search or SOSL request.") class.

#### Signature

public SearchContext()

## SearchContext Properties

The following are properties for SearchContext.

- **[searchPhrase](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_SearchContext.htm#apex_DataSource_SearchContext_searchPhrase)**  
    The user-entered search string as a case-sensitive single phrase, with all non-alphanumeric characters removed.
- **[tableSelections](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_DataSource_SearchContext.htm#apex_DataSource_SearchContext_tableSelections)**  
    List of queries and their details. The details represent the FROM, ORDER BY, SELECT, and WHERE clauses in each SOQL or SOSL query.

### searchPhrase

The user-entered search string as a case-sensitive single phrase, with all non-alphanumeric characters removed.

#### Signature

public String searchPhrase {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.")

### tableSelections

List of queries and their details. The details represent the FROM, ORDER BY, SELECT, and WHERE clauses in each SOQL or SOSL query.

#### Signature

public List<DataSource.TableSelection> tableSelections {get; set;}

#### Property Value

Type: List<[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.")\>