The Heroku AppLink Python app template is a FastAPI web application that demonstrates how to build APIs for Salesforce integration using Heroku AppLink. This template includes authentication, authorization, and API specifications for seamless integration with Salesforce, Data Cloud, and Agentforce.
- Quick Start
- Local Development
- Testing with invoke.py
- Running Automated Tests
- Manual Heroku Deployment
- Heroku AppLink Setup
- Project Structure
- API Documentation
- Additional Resources
- Python 3.8+
pipfor package management- Git
- Heroku CLI (for deployment)
- Salesforce org (for AppLink integration)
Click the Deploy button above to deploy this app directly to Heroku with the AppLink add-on pre-configured.
git clone https://github.com/heroku-reference-apps/applink-getting-started-python.git
cd applink-getting-started-python
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtuvicorn app.main:app --reloadYour app will be available at http://localhost:8000.
- GET /accounts - Retrieve Salesforce accounts from the invoking org.
- POST /unitofwork - Create a unit of work for Salesforce.
- POST /handleDataCloudDataChangeEvent - Handle a Salesforce Data Cloud Change Event.
- GET /docs - Interactive Swagger UI for API documentation.
- GET /health - Health check endpoint.
Visit http://localhost:8000/docs to explore the interactive API documentation powered by Swagger UI.
The bin/invoke.py script allows you to test your locally running app with proper Salesforce client context headers.
./bin/invoke.py ORG_DOMAIN ACCESS_TOKEN ORG_ID USER_ID [METHOD] [API_PATH] [--data DATA]- ORG_DOMAIN: Your Salesforce org domain (e.g.,
mycompany.my.salesforce.com) - ACCESS_TOKEN: Valid Salesforce access token
- ORG_ID: Salesforce organization ID (15 or 18 characters)
- USER_ID: Salesforce user ID (15 or 18 characters)
- METHOD: HTTP method (default: GET)
- API_PATH: API endpoint path (default: /accounts)
- --data: JSON data for POST/PUT requests (as a string)
# Test the accounts endpoint
./bin/invoke.py mycompany.my.salesforce.com TOKEN_123 00D123456789ABC 005123456789ABC
# Test with POST data
./bin/invoke.py mycompany.my.salesforce.com TOKEN_123 00D123456789ABC 005123456789ABC POST /unitofwork --data '{"data":{"accountName":"Test Account", "lastName":"Test", "subject":"Test Case"}}'
# Test custom endpoint
./bin/invoke.py mycompany.my.salesforce.com TOKEN_123 00D123456789ABC 005123456789ABC GET /healthTo get the required Salesforce credentials for testing:
- Access Token: Use Salesforce CLI to generate a session token (
sf org display --target-org <alias> --json | jq .result.accessToken -r). - Org ID: Found in Setup → Company Information or by running
sf org display --target-org <alias> --json | jq .result.id -r. - User ID: Found in your user profile or Setup → Users or by running
sf org display --target-org <alias> --json | jq .result.userId -r.
This project uses pytest for unit testing. To run the tests:
pytest- Heroku CLI installed
- Git repository initialized
- Heroku account with billing enabled (for add-ons)
# Create a new Heroku app
heroku create your-app-name
# Or let Heroku generate a name
heroku createThe app requires two buildpacks in the correct order:
# Add the AppLink Service Mesh buildpack first
heroku buildpacks:add heroku/heroku-applink-service-mesh
# Add the Python buildpack second
heroku buildpacks:add heroku/python# Provision the Heroku AppLink add-on
heroku addons:create heroku-applink
# Set the required HEROKU_APP_ID config var
heroku config:set HEROKU_APP_ID="$(heroku apps:info --json | jq -r '.app.id')"# Deploy to Heroku
git push heroku main
# Check deployment status
heroku ps:scale web=1
heroku open# Check app logs
heroku logs --tail(Instructions for heroku salesforce:connect, heroku salesforce:authorizations:add, and heroku salesforce:publish are identical to the Node.js version and can be referenced from the official documentation.)
Note: This template is designed for educational purposes and as a starting point for building Salesforce-integrated applications. For production use, ensure proper error handling, security measures, and testing practices are implemented.