Skip to content

Client Reference

A client module for managing connections to the Salesforce API.

This module abstracts password and client credentials authentication methods, making it easier to manage connection settings. It extends the simple-salesforce library to provide more flexible connection options.

PasswordAuthSettings pydantic-model

Bases: SalesforceBaseSettings

Define settings for Salesforce API authentication using a username and password.

Fields:

  • auth_method (Literal['password', 'client_credentials'])
  • api_version (str)
  • username (str)
  • password (SecretStr)
  • security_token (SecretStr)
  • domain (Literal['login', 'test'])

ClientCredentialsSettings pydantic-model

Bases: SalesforceBaseSettings

Define settings for Salesforce API authentication using a client ID and client secret.

Fields:

  • auth_method (Literal['password', 'client_credentials'])
  • api_version (str)
  • client_id (str)
  • client_secret (SecretStr)
  • domain (str)

Sf

Sf(*args, **kwargs)

Bases: Salesforce

Provide a Salesforce client.

This class extends the simple-salesforce Salesforce class to abstract authentication methods (password, client credentials) and simplify connection management. It can be used in the same way as the base class due to inheritance.

PARAMETER DESCRIPTION
*args

A list of variable-length positional arguments passed to the parent.

TYPE: Any DEFAULT: ()

**kwargs

A dictionary of arbitrary keyword arguments passed to the parent.

TYPE: Any DEFAULT: {}

connection classmethod

connection(settings)

Establish a connection to Salesforce based on provided settings.

This class method validates the provided settings and handles the connection using either "password" or "client_credentials" authentication methods.

PARAMETER DESCRIPTION
settings

A settings string (in YAML format) or a dictionary containing authentication details. Supported authentication methods are "password" and "client_credentials".

TYPE: str | dict[str, Any]

RETURNS DESCRIPTION
Sf

An instance of the connected Salesforce client.

RAISES DESCRIPTION
ValueError

If the settings are invalid, authentication fails, or the authentication method is not supported.

TypeError

If the settings are not a dictionary or a string.

YAMLError

If the settings string is not a valid YAML format.

HTTPError

If the HTTP request for client credentials fails.