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.

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.

Related Post

Using HTML tag(e.g. line break) in Custom Label Custom Label is a really useful feature in Salesforce, not only can be edited after deployed, but also can be used for making an app multilingual with Translation Workbench. If you want to use HTML tag with it on Visualforce Page, e.g.
tag, the only thing you need to do is using an u...
Create Roll-Up Summary field to count Contacts on ... As we know,roll-up summary field is used to display a value in a master record based on the values of fields in a detail record. The detail record must be related to the master through a master-detail relationship. Unfortunately Account and Contact objects only have a lookup relationship so we cann...
Calculate the difference between two DateTimes in ... In Formula Calculate the second difference between two DateTimes. https://gist.github.com/f7aac81296eab9c473c1 In Visualforce Page Calculate the second difference between two DateTimes. https://gist.github.com/1a9b78306c669542519e In Apex https://gist.github.com/02a89a82060c39f41764 ※A "...
Access Salesforce data via APIs(JSForce) from Outs... At previous post,I had shared you how to setup an 《Awesome Node.js development environment with Heroku and Cloud9》. Today I will continue to share about how to access Salesforce data via APIs from Outside Service. JSforce JSforce (f.k.a. Node-Salesforce) is a isomorphic JavaScript Library utilizi...

Post Tagged with , , , ,