Support Ukraine đŸ‡ș🇩 Help Provide Humanitarian Aid to Ukraine.
For Developers

Deploy a Hasura GraphQL API for Salesforce in minutes

3 min read
CloudAnswers photo
CloudAnswers
Share
TODO

Salesforce API limits can prevent you from using Salesforce data at scale in your other public web projects. As a Salesforce customer, you only get 1,000 api calls per user per 24h period when you use the Salesforce APIs directly.

This article will show you how to get around that by using the open-source Hasura GraphQL engine in front of Salesforce to maximize developer happiness and data throughput.

Overview

We will create a GraphQL API for Salesforce using Heroku and the open-source version of Hasura. You need access to Heroku and Salesforce to make this work.

The following steps will take you between 10-30 minutes depending on your skill level.

Step 1: Launch a new Hasura Heroku instance

Time Required: 2 minutes

This is the fastest way to getting everything configured because the people at Hasura already prepared a heroku deploy button based on their docker images!

Click this link to deploy the app to Heroku: https://heroku.com/deploy?template=https://github.com/hasura/graphql-engine-heroku

Just pick name and click “Deploy”:

Step 2: Heroku Connect

Time Required: 5–10 minutes

The Heroku marketplace has an add-on called “Heroku Connect” (Salesforce acquired the company that offers this app, so it is officially supported and sold by Salesforce). The free level of Heroku Connect allows for 10,000 records which has enough space for many use cases. The paid levels don’t have prices listed, but they’re about $4k/mo from the recent deals I’ve seen done.

“enterprise” means you need to talk to *humans* to get the prices :)

Add the free version: In your app, click the “Resources” tab at the top, then search and add “Heroku Connect”:After the add-on is installed you will connect (OAuth) to your Salesforce instance and select a table to synchronize. It’s self-explanatory for many users, but the official trailhead has explicit steps if you need them: https://trailhead.salesforce.com/content/learn/projects/develop-heroku-applications/set-up-heroku-connect#create-heroku-mappings

In my example I mapped a custom object in Salesforce called “Content__c”:

Table mapping example in Heroku

Do NOT enable “Database -> Salesforce” unless you understand the consequences!

Step 3: Hasura Table Tracking

Time Required: 5 minutes

The last step is to tell Hasura to expose our newly mapped table!

Load the Heroku Hasura app in your browser, click “Data” at the top, switch the schema to “Salesforce” and then click “track” next to your object:

Large, vibrantly colored arrows on a screenshot, how condescending!

With the table “tracked” we can now query it from GraphQL, our setup is done!

Use the API

Switch back to the “GraphQL” tab, select your object in the left panel named “explorer” and execute live queries of your salesforce data:

This UI shown above is just a wrapper on top of the GraphQL APIs that are provided, which means that integrating into existing projects is a snap:You now have a scalable API: Your limits on this setup are probably closer to 1k requests per second instead of 1k per day (the salesforce limit). And even better, your developers can use GraphQL!

This post is part of a series on how to leverage your existing Salesforce data in external tools: https://cloudanswers.com/build-fast-static-sites-with-salesforce-and-netlify/


CloudAnswers photo
CloudAnswers
Share

About CloudAnswers

Salesforce apps, powerful components, custom development, and consulting. Our experienced team helps you to create and modify workflow processes in salesforce.

Related Articles

For Developers

Tips for Becoming a Salesforce Developer

Interested in becoming a Salesforce developer? In this blog post Jagmohan has put together his favorite tips and resources to get started in the world of Salesforce development.

April 4, 2024

6 Min Read

For Developers

Designing User Security and Visibility in Salesforce

Trust and security are at the top of Salesforce's priority list. The platform has everything you need if you're looking to construct a robust user security paradigm. However, this security approach has flaws that an attacker can exploit to gain access to your data. The Salesforce Architect has the duty to ensure that these features are set up correctly.

March 16, 2022

7 Min Read

For Developers

Batch Apex Error Event - CloudAnswers Hackathon

A hackathon is an event usually put together by a tech organization. The event brings programmers together over a specific period to collaborate on a project.

June 28, 2021

5 Min Read