websightsWhat is Heroku? What is it for? How does it integrate with Salesforce? | SEIDOR
Seidor
Personas hablando

January 30, 2023

What is Heroku? What is it for? How does it integrate with Salesforce?

Within Salesforce: Could you have an integration using message queuing? What if I need to open a WebSocket for communication? And could facial recognition be implemented? Yes, yes and yes! And all this without leaving the Salesforce ecosystem, as Heroku has been part of it since 2010.

What is Heroku?

Heroku is a cloud-based Platform as a Service (PaaS) solution that allows clients to focus solely on developing their applications while Heroku handles the underlying infrastructure.

To provide this service, it uses virtual containers responsible for maintaining and running the applications. These virtual containers are fully scalable on demand, both in terms of quantity and capacity.

One advantage of choosing Heroku is its ability to support multiple programming languages. The primary ones used are: Node.js, Ruby, Python, Java, PHP, Go, Scala, and Clojure. However, this list can be expanded by using Heroku Buildpacks, which allow applications to be compiled in many other languages.

lenguas de java

Features Galore (Dynos, CLI…)

Heroku is deeper than one might imagine before getting to know it. At first, you only see the tip of the iceberg. However, some of its most interesting or striking features are worth highlighting:

comandos
  • Git

In any project or development, Git should be indispensable, but with Heroku, it is even more so. Git is used not only for version control but also as the bridge between local development and the Heroku cloud. The standard way to deploy an application to Heroku is with the famous 'git push' command.

  • Dynos

Dynos (no dinosaur jokes allowed!) are what Heroku calls the virtual containers responsible for keeping the application running. There are different types depending on processing capacity, and they can be combined in quantity and type as desired. They are fully scalable on demand—a major advantage for applications that experience traffic spikes on specific dates (Black Friday, Christmas...). It is crucial to keep track of when and how many dynos are active, as Heroku charges per second of processing.

  • CLI

For terminal lovers, Heroku provides its own custom Command Line Interface. It is so powerful that you can quickly perform any task that would otherwise be done through the web interface.

  • Add-ons

Add-ons are tools that complement the application rather than being standalone apps, meaning they can adapt and provide utility regardless of the specific project. While Heroku offers some proprietary Add-ons, many have been developed by partners or third-party companies. These developers benefit by selling their solutions in the marketplace under various pricing tiers based on the features required. This is very similar to how Salesforce and AppExchange operate.

pasos
  • Buttons

Buttons are components, libraries, or application templates that can be deployed to Heroku with a single click. Once the application is deployed via a Button, it can be modified to suit specific needs. This is where Open Source comes into play (at least for Buttons that specify it), as clicking a Heroku Button is equivalent, for example, to performing a fork on GitHub.

4 pasos para deploy

How to create an app with Heroku?

Going from zero to 'Hello World' is actually quite fast on Heroku. The complexity will mainly lie in the application you want to develop, as Heroku handles everything else in a straightforward way.

Applications run on a Heroku server, using the Heroku DNS Server to point to the application's domain (usually name.herokuapp.com).

Let’s look at those simple steps:

  • Install Heroku, log in, and create the app

Heroku can be installed on Linux, Windows, or macOS. First, you'll need to create an account (currently free) and log in using “heroku login”. Creating the app is as instantaneous as typing “heroku create <app-name>”.

  • Develop the application

First of all, you must choose the programming language you will use for development and, of course, code the application—for example, one that says “Hello World”.

  • Procfile

This file is crucial. It is responsible for telling each dyno (and each dyno type) what to execute. It is a list of instructions. For example, if you wrote a Python app and wanted to start a Gunicorn application server to serve a Django or Flask app, the Procfile would contain “web: gunicorn main:app”.

  • Dependencies

Dynos need to know which other libraries (and their specific versions) must be installed along with the application. If you are using Python, for instance, it would be enough to generate an environment requirements file with “pip freeze > requirements.txt”.

  • Link Git

Once Git is initialized locally, you need to link it to the remote repository on Heroku where the cloud version of the application will be stored: “heroku git:remote -a <app-name>”.

  • (Optional) Use a Database

In case the application needs an external database, there is an Add-on called Heroku Postgres that you can start using for free to test it out.

  • And deploy!

That’s it! Only one last step remains: run the command “git push heroku master”.

How do Heroku and Salesforce integrate?

One of Heroku's strengths is its multitude of integration possibilities with Salesforce. Since they are part of the same ecosystem, it would be surprising if it were any other way.

tabla

The most interesting ones are:

  • Heroku Connect

This provides bidirectional data synchronization between Salesforce and an external database. Any data modification made either inside or outside of Salesforce is reflected as if in a mirror. However, the minimum latency is 10 minutes. If something more instantaneous is required, you would need to use the Salesforce Streaming API to achieve 'polling on demand'.

  • External Objects

This integration method is not exclusive to Heroku, as Salesforce External Objects can be used with other external databases. However, with Heroku, it is remarkably simple and fast to configure. It is an interesting solution for saving space in Salesforce by storing data externally. The data is exposed within Salesforce and can be viewed, searched, and related.

  • Apex Callout

Sometimes simplicity is what best fits our needs. A simple HTTP POST call from Apex to an endpoint provided by Heroku can be sufficient if we only need the service hosted on Heroku occasionally.

Use Cases

The primary reason Heroku is marketed is the peace of mind it provides by handling all the infrastructure required to keep a cloud service available, allowing you to focus on developing the application you need.

Common Uses

Some of the most common uses for Heroku include:

  • Salesforce integrations with external databases

We have already evaluated the multitude of possibilities Heroku offers for integrating with Salesforce. The simplicity of configuration, speed, and the confidence of staying within the Salesforce ecosystem are strong reasons to choose Heroku when necessary.

  • Bridge between Salesforce and a mobile application

Mobile applications typically utilize a RESTful API service, which fits perfectly with Heroku-Salesforce integrations.

  • Embedding a web app or external UI in Salesforce

If the application already exists, why rebuild it? Thanks to Heroku, you can load the application into a canvas via an iframe. Heroku guarantees a secure communication protocol.

  • Exposing a REST API to IoT devices

Internet of Things devices are ubiquitous, and the information they collect is highly valuable. Heroku provides the ability to bring that data into Salesforce to leverage it.

Going Beyond

In this blog, we are going to go further and think about bringing atypical needs to Salesforce—those that might be required occasionally and where Apex falls short, such as:

  • Integrating with Message Queues

Integrations based on message queues (MQTT, RabbitMQ…) are increasingly popular as they prevent data loss during periods of collapse or saturation, since messages are stored until they can be processed. One idea would be to use Heroku to transform these messages into Salesforce Platform Events.

  • SDKs

In industrial environments or integrations with legacy machinery, it is common to integrate via SDKs rather than services. Heroku can be a solution to host that SDK and transform it so it can be consumed by a service.

  • Opening a Socket or WebSocket

There are also modern services structured around Sockets. Performing this task from Apex is currently a limitation, as you cannot leave a socket listening for connections in Apex. Regarding WebSockets, they can be used from the frontend, but what if we need them in the backend? Doing this from Apex would be very complicated. This is where Heroku comes into play.

  • Video and Image Handling

Apex falls quite short in this area. We can forgive it; Apex does not focus on images and video—a field of computing where specialization is required to be competitive. Numerous libraries already exist, some open-source like OpenCV or FFMPEG, which handle computer vision to detect movement, specific objects, distance, facial recognition, etc. With Heroku, you are just one step away from including these features within Salesforce.

  • Creating a Proxy to bypass CORS

CORS issues are very common as modern browsers block cross-origin requests unless specific headers are included. A possible solution is to create a Proxy server on Heroku and use it to avoid these errors by acting as an intermediary between the browser and the API server.

  • Scientific Graph Generation

Occasionally, you might need to use statistical or mathematical functions, or generate scientific graphs. While one might consider solutions like Einstein Analytics, sometimes its power (and price) are excessive. Open-source libraries like NumPy or MatPlotLib already exist and can be brought deep into Salesforce using Heroku.

  • Web Scraping

While there are JavaScript solutions, if the solution is needed in Apex, Heroku can assist. There are specialized open-source web scraping libraries like Selenium or Scrapy, which would be just an integration step away (a very small step thanks to Heroku).

Documentation

That concludes this tutorial on how Heroku can help extend Salesforce functionalities. For more information, it is highly recommended to visit the Heroku Dev Center. There you will find all the technical documentation regarding the configuration and use of Heroku. And of course, Trailhead always offers modules to discover more about Heroku or step-by-step guides to reach 'Hello World' in minutes.