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.
1. Open ODBC Data Source Administrator to configure a Data Source Name (DSN).
2. In the Connection dropdown list, select Custom.

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.
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()