Write a Heroku Scheduler batch for MangoDB+Salesforce with Node.js

In previous post,I had shared how to 《Access Salesforce data via APIs(JSForce) from Outside Service》.
In this post I will share about how to write a Heroku Scheduler batch for synchronizing MangoDB data to Salesforce with Node.js, like the below outline picture.
MangoDB+Salesforce ※I have no doubt that there have many ways to do connect between MangoDB and Salesforce, such as 《 Lightning Connect Custom Adapters and MongoDB》By Enrico Murru and 《 Powering Salesforce Lightning Connect with MongoDB》, and I will try and share that in next posts separately.
Here we go.

1. In Salesforce

The Data Model

New a custom object named “MangodbObject” for storing MangoDB data. MangodbObject

2. In Cloud9 IDE

Update package.json

Add async, moment and mongoose to package.json file.

Create batch files

Create “db.js” and “sfdc.js” in root directory with the blow source code.

Depoly to Heroku

Depoly changed files to Heroku as the previous post,《Awesome Node.js development environment with Heroku and Cloud9

3. In Heroku

Add Add-ons

Add MangoLab and Heroku Scheduler to Heroku. Add-ons

Prepare test data of MongoDB

Create a collection named “accounts” and add the following data in MongoLab. Account

Add new job in Heroku Scheduler

Heroku Scheduler

4. Results

Heroku logs

Check Heroku logs with Heroku command “heroku logs”.

Data in Salesforce

MangoDBObject   Salesforce Now we have a batch which synchronizes data everyday from MangoLab to Salesforce. ;)
Enjoy it.

Post Tagged with , , , ,