Use JSforce and Firebase Functions to query Salesforce data

So you want to get some data from Salesforce, quickly, cheaply and without managing any servers? You’re in luck! By using JSforce and Firebase Cloud Functions you can get up and running in no time!

1.0 Things you will need…

1.1 A Salesforce user account (you’ll use this as a service account)

1.2 A Salesforce SOQL query

1.3 Node.js and NPM

Checking which version of Node Firebase recommends

1.4 A code editor

1.5 A Firebase project

Adding a new project in Firebase

2.0 Setting up Firebase Functions

2.1. Install the FIrebase CLI globally with npm:

2.2 Create a folder to house your project on your local machine:

2.3 Change directory to your project:

2.4 Log into Firebase from the CLI:

2.5 Initialise Firebase Functions within your project:

2.6 You will be asked to select a project so choose the one you created just before:

2.7 You will be asked to choose between JavaScript and Typescript, choose JavaScript:

2.8 You will be asked if you want to use ESLint. Don’t, we are just testing things out here. Press n:

2.9 You will be asked if you want to install dependencies with npm. Press Y:

2.10 If everything worked out alright, open your project folder up in VS Code and you should now have a project structure like this:

Simple, clear Firebase Functions project structure!

3.0 Write some code!

3.1 Setting up the project structure

3.2 Authenticating with Salesforce

Copyable code available here

3.3 Querying Salesforce

Copyable code available here

3.4 Handling Responses

Copyable code available here

3.5 Tying our functions together

Copyable code available here

3.6 Update index.js

Copyable code available here

4.0 Run your Firebase Function!

4.1 Serve your function locally

4.2 Deploy your function to the cloud

More about me at | Want to hire me for a one-on-one session?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store