Heroku - 23 API REST Exercice

This lesson is the hands-on exercise for the Salesforce REST API integration. The goal is to build the code that creates a new Account in Salesforce through the native REST API, deploy it to Heroku, send a request to our Heroku app that in turn calls Salesforce to create the Account, and finally verify that the Account was indeed created on Salesforce. Along the way, we learn how to build a Salesforce request from a Heroku app using the jsforce library for Node.js.

The Node.js / Express receiver

The application is an Express server that, on receiving a POST request, builds another request to Salesforce to create an Account. The first lines spin up a new Express server, then we import jsforce, which is the library we will use to authenticate against Salesforce and to issue requests through the REST API. We declare a route POST /account; when a request hits it, the handler connects to Salesforce using the credentials supplied to the app. If the login succeeds, we call conn.sobject('Account').create({...}): the action we reproduce here is create, and the body lists the fields we want to populate — for example Name, Phone and Website. You can of course pick whichever fields you need. Finally a small block handles potential errors, and on success we return the ID of the freshly created object.

app.post('/account', (req, res) => {
  conn.login(user, pass + token, (err) => {
    if (err) return res.status(500).send(err);
    conn.sobject('Account').create({
      Name: req.body.name,
      Phone: req.body.phone,
      Website: req.body.website
    }, (err, ret) => {
      if (err) return res.status(500).send(err);
      res.send(ret.id);
    });
  });
});

Deploy and test with Postman

To deploy, we open a terminal in the project folder and run:

git add .
git commit -m "rest api receiver"
git push heroku master

Once Heroku reports the deploy as successful, we open the Heroku app to retrieve its public URL, then go to Postman, select the POST method, paste the URL and append /account to it. We fill the request body with the fields we want (Name, Phone, Website), and click Send. Back in Salesforce, the Accounts tab now shows the new account with the phone number and the website (for example www.google.com) we provided. The Account has been created end-to-end through the REST API, which validates the integration. That is all for this video — and this concludes the Heroku course. See you in the next one.

Summary

This hands-on exercise teaches how to build a REST API on Heroku that integrates with Salesforce using Node.js and Express. Students learn to deploy code to Heroku, authenticate with Salesforce using a Node.js library, and create account records via REST API requests. The lesson demonstrates the complete workflow: writing the API endpoint, deploying to Heroku, testing with Postman, and validating account creation in the Salesforce database.

Key points

  • Deploy a Node.js Express server to Heroku with Salesforce integration using a dedicated client library
  • Create a REST API POST endpoint that authenticates with Salesforce and creates account records with custom fields (name, phone, website)
  • Implement error handling and return the created object ID on successful account creation
  • Use Postman to test REST API endpoints against your live Heroku application
  • Validate account creation by verifying the data persists in the Salesforce database
  • Understand the flow from HTTP request through Heroku to Salesforce API and back

FAQ

What is the main objective of this Heroku and Salesforce integration exercise?

The exercise teaches how to build a REST API on Heroku that connects to Salesforce, enabling remote account creation via HTTP POST requests without direct Salesforce UI access.

What tools and libraries are required for this lesson?

You need Node.js with Express for the server framework, a Salesforce Node.js client library (for authentication and API calls), Heroku CLI for deployment, and Postman for testing REST endpoints.

How do you verify that the account was successfully created in Salesforce?

After sending a POST request through Postman to your Heroku endpoint, check the Salesforce database directly to confirm the account record exists with the correct fields (name, phone, website).