Skip to content

Update accounts in a target org with data from a source org. The application uses Salesforce functions and the pg_trgm module in Postgres to find duplicated records.

Notifications You must be signed in to change notification settings

chrismarino/account-merge

Repository files navigation

Accounts Sync App

Description

Update accounts in a target org with data from a source org. The application uses Salesforce functions and the pg_trgm module in Postgres to find duplicated records.

Architecture

Architecture

Installation

  1. Log in and set up your Devhub, the org must have Salesforce functions enabled.
sfdx auth:web:login -d -a <alias>

Configure Source Org:

  1. Create the source scratch org
sfdx force:org:create -s -f config/project-scratch-def.json -a sourceorg
  1. Push source code to org
sfdx force:source:push -f
  1. Import Accounts
sfdx force:data:bulk:upsert -i Id -f data/Source.csv -s Account
  1. Create a Heroku app for data resources
heroku create <app-name>
  1. Create Postgres resource
heroku addons:create heroku-postgresql:hobby-dev -a <app-name>
  1. Create Heroku Connect resource
heroku addons:create herokuconnect:demo -a <app-name>
  1. Configure Heroku Connect

Follow documentation from step 4 to configure Heroku connect; use salesforce as the schema(it's the default) and map all the standard fields for the Account Object.

Configure Target Org:

  1. Create the target scratch org
sfdx force:org:create -s -f config/project-scratch-def.json -a targetorg
  1. Push source code to org
sfdx force:source:push -f
  1. Import Accounts
sfdx force:data:bulk:upsert -i Id -f data/Target.csv -s Account
  1. Assign Permission Sets
sfdx force:user:permset:assign -n Accounts_Sync_App
sfdx force:user:permset:assign -n Functions
  1. Create Compute Environment
sf login functions
sf env create compute --connected-org=targetorg --alias=accountssyncenv
  1. Log in to DevHub if you have not already, then Deploy Functions
sf login functions
sf deploy functions -o targetorg
  1. Add Heroku User Collaborator to Functions Account
sf env compute collaborator add --heroku-user <user_email_of_your_heroku_account>
  1. Attach Postgres Database to Compute Environment
heroku addons:attach <postgresql_database_name> -a <compute_environment_name>
  1. Install pg_trgm Module in Postgresql
cd scripts
npm install
heroku config --shell -a <app-name> > .env
node create-extension.js

Usage

Go to your target scratch org and open the Accounts Sync application

Reset Data in the source and target org

To reset the data for the target and source orgs run the following command:

node scripts/reset-orgs.js

This will prompt for both Target and Source Org users as well as a Database URL. The script will then delete all Accounts in both org and upsert the source data and the target data respectivelly. If you do not want to reset a specific org, do not enter the user for that org.

About

Update accounts in a target org with data from a source org. The application uses Salesforce functions and the pg_trgm module in Postgres to find duplicated records.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published