The Best Code I Ever Wrote Was the Code I Stopped Rewriting. Here Are the 3 Repos I Built Instead.

The Best Code I Ever Wrote Was the Code I Stopped Rewriting | Enterprise Architecture
Open Source + Salesforce + AI

The Best Code I Ever Wrote Was the Code I Stopped Rewriting. Here Are the 3 Repos I Built Instead.

After 15 years of enterprise CRM implementations, I packaged the patterns that survived production into three free repos. AI agents that understand governor limits. A migration toolkit that catches broken phone numbers before they hit your org. And a cookbook of automation recipes with actual gotchas sections.

Reading time: ~12 minutes | Published: May 9, 2026 | Published By: Sandip Patel, Salesforce Architect
REPOS 3 Open Source Projects
CODE FILES 58 Production-Ready Files
AGENTS 10 Pre-Built AI Agents
MCP TOOLS 8 Salesforce MCP Server Tools
TL;DR

Three MIT/Apache-licensed repos: (1) SAAF, a Python framework for building AI agents that work natively with Salesforce, including an MCP Server for Claude Desktop; (2) CRM Data Migration Toolkit, an object-mapping and data-cleansing pipeline for CRM migrations; (3) Salesforce Process Automation Recipes, a cookbook of battle-tested Apex, Flow, and integration patterns. All free. All on GitHub.

1
The Problem That Keeps Repeating
Why the same three things break on every project

Every Salesforce implementation has a moment where the team realizes they’re solving a problem that has been solved a hundred times before. The data migration goes sideways because someone forgot to normalize phone numbers. The trigger logic becomes a tangled mess across six files. The AI prototype works great in a demo but blows through governor limits the second it touches real data.

I’ve done this long enough that the pattern is obvious. Three categories of work eat 40-60% of the engineering time on every project, and they’re rarely unique to the org. They’re common problems with common solutions that get rebuilt from scratch each time because there’s no good open source option in the Salesforce world.

PROBLEM 1
AI + SF
Agent frameworks don’t understand Salesforce. Governor limits, FLS, Flows, Bulk API, none of it.
PROBLEM 2
Migration
Data migrations break in the same places. Phone formats, state names, orphaned records, picklist mismatches.
PROBLEM 3
Patterns
Teams keep writing the same trigger framework, the same round-robin logic, the same SLA escalation flow.

Salesforce just open-sourced Agent Script and shipped Agentforce 2.0 with MCP support and multi-model tooling. The direction is clear: AI agents are becoming the primary way enterprises interact with CRM data. But there’s a gap between Salesforce’s native tooling and what independent teams need to build their own agents that work alongside (or instead of) Agentforce.

So I packaged up the patterns that actually worked in production and put them on GitHub. Three repos. All free.

2
Salesforce AI Agent Framework (SAAF)
AI agents that understand governor limits, FLS, and Salesforce metadata

If you’ve tried building AI agents that read and write Salesforce data, you know the gap. LangChain and CrewAI are powerful general-purpose tools, but they have no concept of governor limits, field-level security, or Salesforce object relationships. You end up writing hundreds of lines of glue code to make a simple agent that can score a lead.

SAAF is a Python framework where agents are Salesforce-native from the ground up. They know about SObjects, SOQL, Flows, Platform Events, and the Bulk API. They track API call usage automatically. They enforce FLS. And they log every action to a custom SAAF_Audit_Log__c object so you have a full trail of what the agent did and why.

🤖
Multi-LLM Support

Works with Claude, GPT, Gemini, and local models via Ollama. Swap providers with one line.

🔒
Safety Rails

Dry-run mode, approval gates for destructive operations, FLS enforcement, and governor limit tracking.

🔌
MCP Server

8-tool MCP server that lets Claude Desktop, Cursor, or any MCP client query your Salesforce org directly.

The MCP Server Changes the Workflow

The piece I’m most interested in is the MCP Server. With Salesforce now supporting MCP natively in Agentforce, the protocol is becoming the standard for agent-to-tool communication. SAAF’s MCP Server works the other direction: it exposes your Salesforce org as a set of tools for any MCP-compatible AI client.

In practice, this means you can open Claude Desktop, type “show me all opportunities closing this month over $50K with no activity in the last 14 days,” and Claude writes the SOQL, runs it against your org, and gives you the results. No code, no middleware, no integration platform.

STEP 1
AI Client
Claude Desktop / Cursor
STEP 2
MCP Protocol
Tool discovery + invoke
STEP 3
SAAF MCP Server
8 Salesforce tools
STEP 4
Salesforce Org
Data + Flows + Reports

Pre-Built Agents

The framework ships with three production-ready agents you can use immediately. Each one handles the common patterns (batch processing, error handling, audit logging) and lets you customize the business logic through configuration.

LeadQualificationAgent
Rule-based + AI hybrid scoring

Combines configurable rule scoring (company size, industry, revenue) with LLM qualitative analysis of title, description, and engagement signals. Auto-categorizes leads as Hot, Warm, Nurture, or Disqualified.

CaseRoutingAgent
Content analysis + queue routing

Analyzes case subject and description to determine product area, urgency, and sentiment. Routes to the best matching queue. Detects escalation keywords and auto-elevates priority.

OpportunityScoringAgent
Win probability + risk flags

Predicts close probability by analyzing stage velocity, activity recency, related Tasks/Events, and deal characteristics. Flags at-risk deals with specific risk factors.

Salesforce AI Agent Framework (SAAF)

Python 3.10+ | MIT License | 21 files | MCP Server included

View on GitHub →
3
CRM Data Migration Toolkit
Because every migration breaks in the same places

Here’s the thing about data migrations: they’re not technically hard. They’re operationally brutal. The source system stores phone numbers in 15 different formats. State names are sometimes abbreviations, sometimes full names, sometimes misspelled. The picklist values between HubSpot and Salesforce don’t match. And there are always duplicate records.

This toolkit handles the unglamorous work. You define your field mappings, attach transforms, set up validators, and run the whole thing in dry-run mode to catch problems before a single record touches Salesforce.

13 Built-in data transforms (phone, email, state, date, currency, HTML strip, etc.)
6 Pre-migration validators (required fields, email format, field length, duplicates, date range)
3 Migration templates (HubSpot, Dynamics, Zoho to Salesforce)

The Validation Layer is the Point

The transforms are nice. The templates save time. But the real value is the validation framework. It runs every record through your rules before anything hits Salesforce, and gives you a clear report of exactly what would fail and why.

PYTHONfrom crm_migrate.validators import (
    RequiredFieldValidator,
    EmailFormatValidator,
    FieldLengthValidator,
    DuplicateCheckValidator,
)

validators = [
    RequiredFieldValidator(fields=["Name", "Email"]),
    EmailFormatValidator(field="Email"),
    FieldLengthValidator(sobject="Account"),
    DuplicateCheckValidator(match_fields=["Name", "Website"]),
]

# Catches 156 validation errors BEFORE you load

Every migration runs in dry-run mode by default. You see exactly how many records would be created, how many fail validation, and how many duplicates were found. Then you fix the mapping, run it again, and only commit when the numbers look right.

CRM Data Migration Toolkit

Python 3.10+ | Apache 2.0 License | 15 files | CSV + API sources

View on GitHub →
4
Salesforce Process Automation Recipes
A cookbook of patterns that survived production

This one is less of a tool and more of a reference library. It’s a collection of automation patterns I’ve used across different orgs, documented with the actual business scenario, the code, and the production gotchas that only show up at scale.

The Salesforce community has tons of “how to build a Flow” tutorials. What it lacks is documented patterns for the hard stuff: how to do round-robin lead assignment with timezone awareness, how to chain Queueable jobs to process 500K records, how to build a circuit breaker around an unreliable external API.

APEX PATTERN
Trigger Handler Framework
One trigger per object with recursion guard, per-user bypass via Custom Setting, and consistent handler interface. The pattern most orgs need and most orgs get wrong.
Includes TriggerHandler.cls + AccountTriggerHandler example + full test class
APEX PATTERN
REST Callout with Circuit Breaker
Retry logic with exponential backoff, plus a circuit breaker that stops making callouts when the external service is genuinely down. Uses Custom Setting for state persistence across transactions.
Prevents integration failures from cascading into your org
FLOW RECIPE
Lead Round Robin with Timezone Awareness
Distributes leads evenly across reps. Handles vacation, capacity limits, and source-based routing overrides. Uses Custom Objects for rotation state.
Documented race condition workaround for high-volume orgs
AI-ENHANCED
Case Auto-Classification via LLM
Invocable Apex action that sends case content to an LLM (via Named Credential), parses the structured response, and updates product area, urgency, sentiment, and routing suggestion.
Reduces manual triage time by 15-25 hours/day at 500+ cases/day
FULL RECIPE LIST

The repo includes 20+ recipes across four categories: Flow Recipes (6), Apex Patterns (6), Integration Blueprints (4), and AI-Enhanced Workflows (4). Each recipe includes a README with business scenario, architecture diagram, deployable code, and a gotchas section.

Salesforce Process Automation Recipes

Apex + Flows + LWC | MIT License | 22 files | Community contributions welcome

View on GitHub →
5
The Real Talk
Limitations, rough edges, and what could go wrong

These tools solve real problems, but they’re not finished products. Here’s what you should know before depending on them.

Honest Limitations

!
SAAF is not Agentforce. It’s a complementary tool for teams that want to build custom agents outside the Salesforce platform, or that need multi-LLM flexibility. If you’re already on Agentforce and it covers your use case, you probably don’t need SAAF.
!
The migration toolkit handles CSV well. API connectors are thin. If you need real-time sync or direct API extraction from HubSpot/Dynamics, you’ll need to build the connector layer. The toolkit focuses on the mapping/transform/validate pipeline.
!
Recipe coverage is uneven. The Apex patterns are solid with full test classes. The Flow recipes are documented but don’t include importable Flow XML yet (it’s on the roadmap). The integration blueprints are more like reference architectures than plug-and-play solutions.
!
Tests are minimal. Core logic is tested. Edge cases need more coverage. If you’re putting this in production, add your own tests for your specific use case.

None of these are showstoppers, but I’d rather be upfront about them than have someone find out the hard way. Open source means you can see everything, fix anything, and contribute back.

6
Frequently Asked Questions
Do I need to choose between SAAF and Salesforce Agentforce?
No. They serve different purposes. Agentforce is Salesforce’s native agent platform with the Atlas reasoning engine and deep platform integration. SAAF is for teams that need custom agents with multi-LLM support, or that want to connect external AI clients (Claude Desktop, Cursor) to their Salesforce org via MCP. You can use both in the same org.
What Salesforce editions do these tools work with?
Any edition that supports the REST API (Enterprise, Unlimited, Developer, Performance). The MCP Server and migration toolkit connect via the standard Salesforce REST/Bulk APIs. The Apex recipes require the ability to deploy custom code.
How long does it take to set up the MCP Server for Claude Desktop?
About 10 minutes. Install the package (pip install salesforce-ai-agent-framework), add your Salesforce credentials to the Claude Desktop config file, and restart Claude. The README has the exact JSON block to paste.
Is the migration toolkit safe to use on production data?
It runs in dry-run mode by default, so you see a complete preview of what would happen before committing. When you do run it for real, every migration gets a rollback log saved as JSON. That said, always test on a sandbox first.
What’s the biggest mistake people make with the trigger handler framework?
Not using the recursion guard. The framework includes a static Set<Id> that tracks which records have been processed in the current transaction. If you skip it, workflow field updates and process builders will re-fire your trigger and create infinite loops. The example AccountTriggerHandler shows the correct pattern.
Can I contribute a recipe or migration template?
Yes. All three repos have CONTRIBUTING.md files with guidelines and issue templates. The areas where contributions would be most useful: migration templates for CRMs other than HubSpot (Dynamics, Zoho, Pipedrive, Freshsales), industry-specific agent recipes, and performance benchmarks from high-volume orgs.

Leave a reply

Your email address will not be published. Required fields are marked *