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.

Related Post

Salesforce Mass Editor (Chrome Extension) – ... This's my second Chrome Extension (First one is HERE) this year, named "Salesforce Mass Editor" and it supports for doing the below things : ・Makes any Salesforce list view to be a powerful mass editor. ・Mass insert, mass clone, mass update, mass delete, ALL-IN-ONE. ・Export record data to CSV fi...
Setup an awesome Salesforce developer environment ... Why Sublime Text 3 ? I've been working with Force.com for about 2 years, and always using Eclipse+Force.com IDE(See here, Eclipse Force.com IDE Installation)as my development environment. I don't think it is difficult to use, but it could more friendly. For example: 1. It doesn't support APEX an...
Instantiating an Apex class based on dynamic strin... Somtimes we need to instantiate a Apex class by dynamic value in Salesforce, which can make our program more modular and more readable, such as the below case : 1. Each Contact has its socail fields : "Type__c" and "AccessToken__c" 2. Needs to request its profile via socail api in Apex Firs...
Using Aggregate SOQL queries/results in Batch Apex In previous post, we had created a schedulable batch apex that implements Database.Batchable in Salesforce, but if you want to use SOQL having aggregate functions like SUM(), MAX(), COUNT() on results grouped by “GROUP BY” clause in start execution, changing to interface Database.Ba...

Post Tagged with , , , ,