Connect to a Salesforce custom domain

Last modified: July 7, 2025

Custom domains in Salesforce are personalized URLs that organizations configure to enhance their branding and provide secure access to Salesforce services. These domains replace the default Salesforce URLs (https://login.salesforce.com or https://test.salesforce.com) with a company-specific address (for example, https://yourcompany.my.salesforce.com), offering both functionality and branding benefits.

Configure a connection to a Salesforce custom domain

1. Open ODBC Data Source Administrator to configure a Data Source Name (DSN).

2. In the Connection dropdown list, select Custom.

Custom-type connection

3. In the Server field, replace the default login URL (https://test.salesforce.com) with your custom URL (for example, https://yourcompany.my.salesforce.com).

4. Select the authentication method and enter the corresponding credentials based on your selection.

5. Optional: Select Test Connection to verify the connection settings.

Once the DSN is configured, use your preferred tools (for example, R, Excel, or SQL-based applications) to connect and query Salesforce data.

Example: Connect to a Salesforce custom domain in Python using pyodbc

import pyodbc

# Define connection parameters
dsn =            "your_DSN"                       # DSN configured for the custom domain
Server =         "yourcompany.my.salesforce.com"  # Custom Salesforce domain
User ID =        "your_username"                  # Salesforce username
Password =       "your_password"                  # Salesforce password
Security Token = "your_security_token"            # Salesforce security token

# Establish the connection
conn = pyodbc.connect(f"DSN={dsn};UID={username};PWD={password}")

# Query Salesforce data
query = "SELECT Id, Name FROM Account LIMIT 10"
cursor = conn.cursor()
cursor.execute(query)

# Fetch and print the results
for row in cursor.fetchall():
    print(row)

# Close the connection
conn.close()