Skip to content

Instantly share code, notes, and snippets.

@scottpersinger
Last active December 20, 2015 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottpersinger/6118327 to your computer and use it in GitHub Desktop.
Save scottpersinger/6118327 to your computer and use it in GitHub Desktop.
try this one

cloudconnect is an add-on that connects your Salesforce account to your Heroku app.

Cloudconnect creates a relational database containing your Salesforce data, and synchronizes data changes in both directions to that database.

By using cloudconnect, you can interact with your Salesforce data by connecting to a PostgresSQL or Mysql database using your favorite language or web framework like Rails, Django, or PHP.

Provisioning the add-on

cloudconnect can be attached to a Heroku application via the CLI:

$ heroku addons:add cloudconnect:trial
-----> Adding cloudconnect:trial to sharp-mountain-4005... done, v18 (free)

Once cloudconnect has been added, you must complete the provisioning process through the cloudconnect web interface:

$ heroku addons:open cloudconnect:trial

To provision cloudconnect, follow these steps:

  1. Choose your database type, Heroku PostgreSQL or Amazon RDS Mysql
  2. Authenticate to your Salesforce account
  3. Choose one or more Salesforce objects to synchronize
  4. If you plan on running the cloudconnect demo Rails app, please map your Account and Contact objects

Note that by default your database will be read only, which means that any writes you perform will not be sent to Salesforce. If you want to make changes to your Salesforce data you must enable Read/Write mode via the cloudconnect portal.

Once initial setup is complete, a CLOUDCONNECT_URL setting will be available in the app configuration and will contain the connection URL for connecting to your database instance. This can be confirmed using the heroku config:get command.

$ heroku config:get CLOUDCONNECT_URL
postgresql://user:pass@host/database

Local setup

Now try testing that you can connect to the cloudconnect database. You will need to have the Ruby Sequel gem installed.

$ export CLOUDCONNECT_URL=`heroku config:get CLOUDCONNECT_URL`
$ irb
> require 'sequel'
> db = Sequel.connect(ENV['CLOUDCONNECT_URL'])
> db.tables

Rails app

Download the Cloudconnect Rails demo app https://github.com/cloudconnect/cloudconnectdemo.git

$ git clone https://github.com/cloudconnect/cloudconnectdemo.git

Create a database for the Rails app:

$ psql
# create database cloudconnectdemo_development;
CREATE DATABASE
# create user cloudconnectdemo;
CREATE ROLE
# grant all privileges on database cloudconnectdemo_development to cloudconnectdemo;
GRANT

Set the CLOUDCONNECT_URL variable in your environment to point your cloudconnect database.

If you haven't done so yet, you should open the cloudconnect admin site and map your Contact and Account objects from Salesforce.

Now test that you can access your Salesforce data. Note that when you start the Rails app it will first connect to its own database. This one is configured in database.yml. Then it will connect to the cloudconnect database.

$ rails console
Loading development environment (Rails 3.2.13)
> Account.count
 => 25 
>

You should see a count of your Salesforce Account objects. Now go ahead and run the rails web server ( rails server ) and open localhost:3000. The demo app provides pages for browsing your Accounts and Contacts and seeing some basic details of each record.

Under the hood

The sample app contains a reusable mechanism for accessing the cloudconnect database tables. An abstract base class is defined in salesforce_model.rb which connects to the cloudconnect database:

class SalesforceBase < ActiveRecord::Base
  self.abstract_class = true
  establish_connection ENV['CLOUDCONNECT_URL']
end

And each class to access a cloudconnect table inherits from the base class:

class Account < SalesforceBase
  self.table_name = 'account'
  has_many :contacts, :primary_key => "sfid", :foreign_key => "accountid"
end

Note how we related Accounts to Contacts via the sfid column. This is the actual Salesforce id. The records in the cloudconnect database also use Rails-standard autoincrement id columns, so specifying the foreign key this was isn't strictly neccessary.

Migrating between plans

note Application owners should carefully manage the migration timing to ensure proper application function during the migration process.

Migrating to a higher level cloudconnect plan may require provisioning a larger capacity database. Please contact cloudconnect so that we can help migrate your database when you're ready to upgrade plans.

Use the heroku addons:upgrade command to migrate to a new plan.

$ heroku addons:upgrade cloudconnect:trial:newplan
-----> Upgrading cloudconnect:trial:newplan to sharp-mountain-4005... done, v18 ($49/mo)
       Your plan has been updated to: cloudconnect:trial:newplan

Removing the add-on

cloudconnect can be removed via the CLI.

warning This will destroy your cloudconnect database, and everything stored in it will be lost!

:::term
$ heroku addons:remove cloudconnect:trial
-----> Removing cloudconnect:trial from sharp-mountain-4005... done, v20 (free)

Note that if you have stored any non-sychronized data in your cloudconnect database, then you should backup your database before destroying it.

Support

All cloudconnect support and runtime issues should be submitted via on of the Heroku Support channels. Any non-support related issues or product feedback is welcome at [support@cloudconnect.com].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment