Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python code samples used for the Dreamforce 2025 Heroku Mini Hack

NotificationsYou must be signed in to change notification settings

heroku-examples/df25-heroku-minihack-code-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

Requirements

  • 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.

Local Development and Testing

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.txt

Run 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",...}}

Deploying and Testing from Apex and Flow

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.11

The 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.

Invoking from Apex

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp