Skip Navigation
Show nav
Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
Hide categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Developer Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Troubleshooting Node.js Apps
      • Working with Node.js
      • Node.js Behavior in Heroku
    • Ruby
      • Rails Support
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • PHP Behavior in Heroku
      • Working with PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Vector Database
    • Working with AI
    • Heroku Inference
      • AI Models
      • Inference Essentials
      • Inference API
      • Quick Start Guides
    • Model Context Protocol
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Integrating with Salesforce
  • Make Apex and Workflow Callouts to Your API

Make Apex and Workflow Callouts to Your API

English — 日本語に切り替える

Last updated April 28, 2023

Table of Contents

  • When to Use
  • Apex HTTP Callouts
  • Outbound Messaging
  • Limits & Considerations
  • Learn More

There are two primary methods for calling into a Heroku app with an API, based on an activity in Salesforce:

  • Apex HTTP callouts for programmatically making REST calls.
  • Workflow outbound messages for declaratively making SOAP calls.

Either way, the Heroku app receives a request with the event details payload, and then performs the action.

When to Use

You want a REST API integration based on object updates in the Salesforce org.

Apex HTTP Callouts

With Apex callouts, you can tightly integrate your Apex with an external service, in this case, an app running on Heroku. Apex provides facilities for serializing objects into JSON and asynchronously calling HTTP endpoints. For example, here’s a helper class that can serialize an object and asynchronously POST the data to a Heroku endpoint:

public class Helper {
  public static String jsonContent(List<Object> triggerNew) {
    String newObjects = '[]';
    if (triggerNew != null) {
      newObjects = JSON.serialize(triggerNew);
    }
    String content = '{"new": ' + newObjects + '}';
    return content;
  }
  @future(callout=true) public static void callout(String url, String content) {
    Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint(url);
    req.setMethod('POST');
    req.setHeader('Content-Type', 'application/json');
    req.setBody(content);
    h.send(req);
  }
}

You can then invoke that method by attaching a trigger:

 trigger NewContactHerokuTrigger on Contact (after insert) {
  String endpoint = 'https://example-app-1234567890ab.herokuapp.com/api/action';
  String content = Helper.jsonContent(Trigger.new);
  Helper.callout(endpoint, content);
}

Ensure that your Heroku application listens on the same API endpoint, and that it implements the appropriate action on receiving an HTTP POST. You can additionally send a session ID to allow the Heroku app to make calls back into Salesforce using the Salesforce REST API.

Outbound Messaging

With outbound messaging, you can configure Salesforce to automatically send messages (together with field values) to a designated external application endpoint, such as a Heroku app, whenever a specified set of fields change. Outbound messaging is part of the workflow rule functionality in Salesforce. Workflow rules watch for specific kinds of field changes, and trigger automatic Salesforce actions, such as sending email alerts, creating task records, or sending an outbound message.

With workflow, you declaratively define a rule and a callout to an external system. The rule can be connected to any Salesforce object.

Limits & Considerations

Calling into Heroku from Salesforce tightly couples an endpoint on Heroku with Apex code in production. This method can make debugging more difficult. For more scalable and resilient integrations, we recommend using Salesforce Platform Events.

Pay attention to API limits, as many of the scenarios described here can impact a Salesforce limit (for example, Apex Triggers have CPU time limits, which affect how often an integration can fire).

Security and Heroku/Salesforce integrations shows how to secure this integration.

Learn More

  • See Invoking Callouts using Apex in the Apex Developer Guide.
  • See Setting Up Outbound Messaging in the SOAP API Developer Guide

Keep reading

  • Integrating with Salesforce

Feedback

Log in to submit feedback.

Using the Salesforce REST API with Heroku Publish and Subscribe to Salesforce Platform Events

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2025 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices