🤝 Sync Salesforce leads and opportunities to PostgreSQL with backfill and incremental ETL

⚡ 98 views · 🤝 CRM & Sales Operations

Description

Salesforce Leads & Opportunities to PostgreSQL (Backfill & Incremental Sync ETL)

This workflow extracts Lead and Opportunity data from Salesforce, transforms and normalizes the data, and loads it into PostgreSQL as a structured data bank for reporting and analytics.

It is designed for scalable data ingestion and supports both historical backfill and incremental sync in a single workflow.


Use Case

This workflow is suitable when you need to:


Two Input Modes

1. Historical Backfill (Manual Trigger)

Run once to populate historical data.


2. Incremental Sync (Schedule Trigger)

Runs automatically (e.g. daily).


Batch Processing

Date ranges are processed in weekly batches.

This helps:


Core Workflow Logic

1. Data Extraction


2. Phone-Based Routing

Records are split into two paths:

This ensures no data is lost even if phone is missing.


3. Phone Normalization (+62)

Phone numbers are standardized into:

+62XXXXXXXXXX

Steps:

This uses Indonesia’s International Direct Dialing (IDD) code: +62


4. Opportunity De-duplication

This ensures clean merging and avoids duplicate enrichment.


5. Lead–Opportunity Merge

Merge is done using normalized phone fields:

Behavior:

Records without phone:


6. Data Standardization

All records are transformed into a unified schema:


7. Upsert to PostgreSQL

Behavior:

Ensures:


Data Flow Summary

Salesforce (Lead + Opportunity) → Date Filtering → Batch Processing (weekly) → Phone Routing → Phone Normalization (+62) → Opportunity Deduplication → Lead–Opportunity Merge → Data Standardization → PostgreSQL (Upsert)


Setup Requirements

Before using this workflow, prepare the following:

1. Salesforce


2. PostgreSQL


3. n8n Environment


4. Date Configuration (Backfill)


5. Schedule Configuration (Incremental)


Minimal PostgreSQL Table Schema

CREATE TABLE n8n_salesforce_data ( sf_id TEXT PRIMARY KEY, Source_Object TEXT, CreatedDate TIMESTAMP, CreatedById TEXT, Name TEXT, Phone TEXT, Clean_Phone TEXT, Email TEXT, LeadSource TEXT, Status TEXT, StageName TEXT, OwnerId TEXT, AccountId TEXT, Amount NUMERIC, synced_at TIMESTAMP DEFAULT NOW() );


Important Notes


Known Limitations



Summary

This workflow provides a reliable and scalable way to:

It is best suited for teams building a lightweight data warehouse layer on top of Salesforce.

đź”— Nodes Used

Postgres, Salesforce, Schedule Trigger

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup