---
schema_version: "1"
id: 02cca9fd623bfa617bae1de8c3c07daf80ea95e7ce055dc8f5adb7c336e46233
title: Create a Sample DataSource.Provider Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_connector_start_provider_class.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connector_start_provider_class.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 350f4f960d91c6ab7df686b7c4d4d31902fb04c5b24c5be13c94477beb8ef1cc
description: Now you need a class that extends and overrides a few methods in DataSource.Provider.
---
# Create a Sample DataSource.Provider Class

Now you need a class that extends and overrides a few methods in DataSource.Provider.

Your DataSource.Provider class informs Salesforce of the authentication and functional capabilities that are supported by or required to connect to the external system.

global with sharing class SampleDataSourceProvider extends DataSource.Provider {

If the external system requires authentication, Salesforce can provide the authentication credentials from the external data source definition or users’ personal settings. This example specifies that the external system doesn’t require authentication, but also supports OAuth authentication. To do so, it returns AuthenticationCapability.ANONYMOUS and AuthenticationCapability.OAUTH in the list of authentication capabilities.

The getAuthenticationCapabilities method should always return the same list of authentication types regardless of user, org, or context.

global override List<DataSource.AuthenticationCapability>
        getAuthenticationCapabilities() {
        // Best Practice: Always return a static list of authentication types
        // Don't query the database, make callouts, or use dynamic logic
        List<DataSource.AuthenticationCapability> capabilities =
            new List<DataSource.AuthenticationCapability>();
        capabilities.add(DataSource.AuthenticationCapability.ANONYMOUS);
        capabilities.add(DataSource.AuthenticationCapability.OAUTH);
        return capabilities;
    }

This example also specifies that the external system allows SOQL queries, SOSL queries, Salesforce searches, upserting data, and deleting data.

- To allow SOQL, the example declares the DataSource.Capability.ROW\_QUERY capability.
- To allow SOSL and Salesforce searches, the example declares the DataSource.Capability.SEARCH capability.
- To allow upserting external data, the example declares the DataSource.Capability.ROW\_CREATE and DataSource.Capability.ROW\_UPDATE capabilities.
- To allow deleting external data, the example declares the DataSource.Capability.ROW\_DELETE capability.

The getCapabilities method should always return the same list of capabilities regardless of configuration or data.The returned capabilities should never change based on runtime conditions, user context, dynamic queries, or any other conditions.

global override List<DataSource.Capability> getCapabilities() {
        // Best Practice: Return a static list of functional capabilities
        // Don't query the database, make callouts, or use dynamic logic
        List<DataSource.Capability> capabilities = new
        List<DataSource.Capability>();
        capabilities.add(DataSource.Capability.ROW\_QUERY);
        capabilities.add(DataSource.Capability.SEARCH);
        capabilities.add(DataSource.Capability.ROW\_CREATE);
        capabilities.add(DataSource.Capability.ROW\_UPDATE);
        capabilities.add(DataSource.Capability.ROW\_DELETE);
        return capabilities;
    }

![Warning](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/images/icon_note_warning.png)

#### Warning

When you call the getAuthenticationCapabilities or getCapabilities methods, be sure the returned list always contains the same values. Never use a SOQL query, callout, or any conditional logic that changes the returned values based on runtime conditions. Returning varying lists of authentication capabilities or capabilities for an external system can lead to errors that are difficult to troubleshoot.

Lastly, the example identifies the SampleDataSourceConnection class that obtains the external system’s schema and handles the queries and searches of the external data.

global override DataSource.Connection getConnection(
        DataSource.ConnectionParams connectionParams) {
        return new SampleDataSourceConnection(connectionParams);
    }
}

- [← Previous](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connector_start_connection_class.htm "Create a Sample DataSource.Connection Class")
- [Next →](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connector_start_setup.htm "Set Up Salesforce Connect to Use Your Custom Adapter")

#### See Also

- [_Apex Reference Guide_: Provider Class](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_class_DataSource_Provider.htm "Apex Reference Guide: Provider Class - HTML (New Window)")