Salesforce Data Automation Pipeline
Salesforce had 10,000+ records with duplicates and stale data everywhere. Built a sync, dedup, and enrichment pipeline that brought accuracy to 99.7%.
99.7% accuracy
The Client's Problem
My Approach
The Workflow Breakdown
Lead creation trigger — A Record-Triggered Flow fires on Lead insert. It checks for duplicates using a fuzzy match on email domain + company name, enriches via a Clearbit Apex callout, assigns territory using the Territory Matrix custom object, triggers Einstein Lead Scoring, and routes to the appropriate rep queue. Processing time: under 3 seconds.
Territory Assignment Matrix — A custom object storing territory rules as records rather than hardcoded logic. Each record defines a combination of geography (state/region), industry vertical, and deal size range, mapped to a territory and rep queue. The sales manager updates territories by editing records — no developer needed.
Lead enrichment callout — An Apex class makes a synchronous callout to Clearbit's API on Lead creation. It populates company size, industry, annual revenue, technology stack, and social profiles. If Clearbit returns no match, the Lead is flagged for manual enrichment rather than blocking the flow.
Einstein Lead Score integration — After enrichment, the Flow triggers Einstein Lead Scoring recalculation. Leads scoring 80+ are auto-flagged as "Hot" and trigger an immediate Slack notification to the assigned rep via a Platform Event.
Opportunity stage automation — An Apex trigger on Task, Event, ContentDocumentLink, and OpportunityLineItem objects detects stage-change signals. Each signal maps to a stage transition: logged call → Discovery, attached proposal → Proposal/Price Quote, completed pricing flow → Negotiation, signed contract → Closed Won. The trigger respects manual overrides and never moves stages backward.
Discount approval Screen Flow — A Screen Flow embedded in the Opportunity Lightning page. The rep enters discount percentage and justification. The Flow evaluates the discount against Custom Metadata Type rules, determines the approval tier, and either auto-approves (with Chatter post) or submits to the appropriate approval process. Each approval step has email notifications, a 24-hour SLA timer, and automatic escalation.
Approval process architecture — Three Apex-driven approval processes (Manager, VP+Finance, CEO) with custom email templates showing deal context, competitive landscape, and financial impact. Approvers can approve/reject from email. Rejection requires a reason that posts to the Opportunity Chatter feed so the rep can adjust and resubmit.
Nightly forecast batch job — A scheduled Apex batch class runs at 2 AM, querying all open Opportunities and calculating weighted pipeline using historical stage-specific win rates per segment. Results are upserted into a custom Forecast__c object partitioned by month, quarter, segment, territory, and rep. The batch handles governor limits by processing 200 records per execution with stateful tracking.
Lightning Dashboard — A multi-component dashboard pulling from the Forecast object: pipeline waterfall chart, forecast vs quota by rep, win rate trends by segment, average deal velocity by stage, and discount frequency analysis. Auto-refreshes every 4 hours.
Data quality automation — A scheduled Flow runs daily, scanning for Opportunities with missing required fields, stale stages (no activity in 14+ days), and orphaned Contacts. It auto-creates Tasks assigned to the Opportunity owner for each data quality issue found.
Platform Event notifications — Custom Platform Events fire for high-priority actions: hot lead assignment, large deal stage changes, discount approvals/rejections, and forecast threshold alerts. A Slack integration subscribes to these events and posts to appropriate channels.
Deployment & testing — All automation deployed via Salesforce CLI with a full Apex test suite (94% code coverage). Change sets are version-controlled in Git with a staging sandbox for QA before production deployment.
Results & Impact
- Sales cycle: Average reduced from 34 days to 21 days, primarily from automated stage
- Data accuracy: Improved from 67% complete records to 98%, driven by auto-enrichment on
- Forecast accuracy: Improved from ±35% to ±8% variance vs actuals. The CEO now makes
- Discount governance: 100% of discounts now flow through the approval process with full
- Rep productivity: 40% more pipeline generated per rep per quarter, attributed to
- Revenue impact: $180K in annual revenue attributed to faster deal velocity — deals that
- Admin overhead: The RevOps team went from spending 15 hours/week on data cleanup and
Technical Highlights
- Record-Triggered Flow architecture — Bulkified Lead processing handling creation,
- Dynamic Territory Assignment Matrix — Admin-configurable territory rules stored as custom
- Tiered discount approval engine — Screen Flow with Custom Metadata Type-driven rules,
- Multi-object stage progression trigger — A single Apex trigger class monitoring four
- Scheduled forecast batch processing — Apex batch class calculating weighted pipeline using
- Platform Event-driven notifications — Real-time event publishing for high-priority CRM
Tools Used
Salesforce (Flows, Apex, Lightning, Einstein), Salesforce CLI, Clearbit API, Slack API, Platform Events, Custom Metadata Types, SOQL, Apex Test Framework, Git, VS Code