Salesforce is a Customer Relationship Management "CRM" web application. This example uses the API to query the CRM.
This example uses Python and is a command line application
Simple Salesforce is a basic Salesforce.com client built for Python. It uses username, password and security token authentication via SOAP to generate a session Id used for subsequent REST APIs calls. See sfdc-go for an example of using OAuth2 and Salesforce Connected App's Consumer Key and Consumer Secret and the deployment's Salesforce instance Url. Simple Salesforce supposedly has OAuth support but I have not tested it.
Credentials include username, password, and token. They are read as environment variables which you place in .zshrc
or .bashrc
# set SalesForce environment variables
export SALESFORCE_USERNAME_1=""
export SALESFORCE_PASSWORD_1=""
export SALESFORCE_SECURITY_TOKEN_1=""
Retrieve the security token from the Salesforce UI, View Profile -> Settings -> Reset My Security Token
The app allows up to 2 Salesforce deployments. When the app starts, the first one entered is loaded. There is an action in the CLI to switch to another deployment if environment variables have been entered.
# set environment variables
export SALESFORCE_USERNAME_1=""
export SALESFORCE_PASSWORD_1=""
export SALESFORCE_SECURITY_TOKEN_1=""
export SALESFORCE_USERNAME_2=""
export SALESFORCE_PASSWORD_2=""
export SALESFORCE_SECURITY_TOKEN_2=""
Register for a complimentary developer account to use with Salesforce API testing
cd
into the repo directory and run the app
python3 salesforce.py
Alternatively, see the dev container approach below which autostarts the app.
The app runs as a while loop prompting the user for actions like:
- creating & updating accounts, contacts, opportunities, opportunity contact roles and tasks
- describing the account, contact, opportunity, and contact role object schemas
- searching Salesforce cccount records by the Name column with an option to retrieve contacts
- deleting accounts, contacts and opportunity contact roles
- searching contacts by name, title, email with an option to update them
- show picklists values for account, contact, opportunity and contact role objects
- allow picklist support for: lead source (contact), type (account), industry (account), Subject (task)
- a global settings for additional account and contact columns to retrieve.
- change salesforce deloyments (up to 2)
Currently am not providing delete functionality for opportunities (revenue) by design.
Notice the Dockerfile
and devcontainer.json
which uses a slim Python container image, adds the simple_salesforce
module with pip
in the Dockerfile, and passes the Salesforce authentication environment variables into the dev container.
This approach frees you up from having a specific Python version and module on your local machine e.g., Mac and let the dev container set all of this up. You do still need to set the environment variables locally which is more secure and better than putting into the repo with .gitignore. ☠️
simple_salesforce Python package
This project is licensed under the MIT License
Please note that this program is not actively maintained or tested. While it may work as intended, it's possible that it will break or behave unexpectedly due to changes in dependencies, environments, or other factors.
Use this program at your own risk, and be aware that:
- Bugs may not be fixed
- Compatibility issues may arise
- Security vulnerabilities may exist
If you encounter any issues or have concerns, feel free to open an issue or submit a pull request.