- Notifications
You must be signed in to change notification settings - Fork0
heroku-examples/df25-heroku-minihack-code-python
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Important
The actions in this repository are used in aSalesforce Dreamforce 25 Heroku Mini Hack. They're here to help people who did the minihack challenge, and have access to the minihack org and its objects, apps, and agents. So, these examples won't work outside the minihack. Also, the steps below are just for reference and won't work unless you use them in an org that has the correct objects already deployed. If you want to explore Heroku in the context of Agentforce please check out thistutorial and also further sampleshere.
- Python 3.8+ and pip
- Heroku login
- Heroku CLI installed
- Heroku AppLink CLI plugin is installed
- Salesforce CLI installed
- Login information for one or more Scratch, Development or Sandbox orgs containing the Dreamforce 2025 Heroku Mini Hack apps.
Code invoked from Salesforce requires specific HTTP headers to connect back to the invoking Salesforce org. The Heroku AppLink Python SDK and CLI can be used to simulate requests from Salesforce with the correct headers, enabling you to develop and test locally before deploying to test from Apex, Flow, or Agentforce.
First, set up your Python environment:
python -m venv venvsource venv/bin/activatepip install -r requirements.txtRun the following commands to locally authenticate and run the sample:
sf org login web --alias my-orguvicorn app.main:app --host 127.0.0.1 --port 8080
In a new terminal window, you can useheroku applink:functions:exec to test your functions. Substitute the Id values for validContact andVehicle Id records from your Salesforce org.
heroku applink:functions:exec -a YOUR_HEROKU_APP_NAME -u my-org -p'{"customerId": "0035g00000XyZbHAZ","vehicleId": "a04Hs00002EMj9PIAT","maxInterestRate": 0,"downPayment": 1000,"years": 3}' --"/api/calculateFinanceAgreement"
You should see output similar to this:
{"recommendedFinanceOffer":{"finalCarPrice":41800.0,"adjustedInterestRate":3.5,"monthlyPayment":...}}Run the following command substituting the Id values for a validFlight record from your Salesforce org.
heroku applink:functions:exec -a YOUR_HEROKU_APP_NAME -u my-org -p'{"flightId": "a02Hs00001D2QtLIAV"}' --"/api/calculateCarbonFootprint"
You should see output similar to this:
{"flight":{"flightNumber":"...","departureAirport":"SFO","arrivalAirport":"LAX",...}}To test from Apex, Flow and other tools within your Salesforce org you must deploy the code and import it into your org.
First, create a.python-version file to specify the Python version for Heroku:
3.11The following commands create a Heroku application and configure the Heroku Integration add-on.
heroku creategit push heroku main
Next install and configure the Heroku Integration add-on:
heroku addons:create heroku-integrationheroku buildpacks:add heroku/pythonheroku buildpacks:add https://github.com/heroku/heroku-buildpack-heroku-integration-service-meshheroku salesforce:connect my-org --store-as-run-as-user# You will need to regenerate an api-docs.yaml for the python app if you want to re-import# heroku salesforce:import api-docs.yaml --org-name my-org --client-name ActionsService
Once imported grant permissions to users to invoke your code using the followingsf command:
sf org assign permset --name ActionsService -o my-org
Deploy the Heroku application and confirm it has started.
git push heroku mainheroku logs --tail
Navigate to your orgsSetup menu and search forHeroku then clickApps to confirm your application has been imported.
Now that you have imported your Heroku application. The following shows an Apex code fragment the demonstrates how to invoke your code in an synchronous manner (waits for response).
ExternalService.ActionsServiceservice=newExternalService.ActionsService();ExternalService.ActionsService.calculateFinanceAgreement_Requestrequest=newExternalService.ActionsService.calculateFinanceAgreement_Request();ExternalService.ActionsService_FinanceCalculationRequestbody=newExternalService.ActionsService_FinanceCalculationRequest();request.body=body;request.body.vehicleId='a04Hs00002EMj9PIAT';System.debug('Final Car Price:'+service.calculateFinanceAgreement(request).Code200.recommendedFinanceOffer.finalCarPrice);
Inspect the debug log output sent to to the console and you should see the generated Quote ID output.
About
Python code samples used for the Dreamforce 2025 Heroku Mini Hack
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.