GTM Galaxy

Article

Mapping the Blast Radius: Building a CRM Dependency Analyzer with Claude Code

CRM schema bloat isn't just an aesthetic problem for RevOps; it’s a tax on every new automation and a landmine for every integration. We've all seen it: Lead_Source_v2_FINAL_USE_THIS sitting next to three other versions of the same field.

We leave these zombie fields alone because manual auditing is high-stakes guesswork. Salesforce’s native "Where is this used?" button is a start, but it doesn't give you a holistic view of the blast radius across Apex, Flows, and validation rules. HubSpot’s property usage tool is similarly siloed.

By treating our CRM metadata as code and using Claude Code to build a local dependency parser, we can move from "I hope this doesn't break routing" to a data-backed deprecation workflow.

The Technical Constraint: Metadata Visibility

To build an analyzer, you have to navigate the specific ways Salesforce and HubSpot expose their architectural skeletons.

Salesforce: The Tooling API

The MetadataComponentDependency object in the Salesforce Tooling API is the gold mine here. It allows you to query relationships between metadata components—for example, which Custom Field is referenced by which Apex Class or Flow.

However, it comes with three major friction points:

  1. The 2,000 Record Limit: You cannot query the entire dependency table in one go. You have to paginate or chunk by metadata type.
  2. No Bulk API: You’re stuck with synchronous Tooling API queries, which are slower and more restrictive.
  3. Custom Only: It generally ignores standard fields (like Industry or AccountSource), focusing on your custom cruft.

HubSpot: JSON Inspection

HubSpot doesn't offer a relational dependency table. Instead, you have to fetch the full JSON definitions of every workflow, list, and form via the Automation and CRM APIs. A property's "dependency" is simply its internal_name appearing in a filter, action, or branch logic in those JSON payloads.

Building the Analyzer with Claude Code

This is where a GTM operator’s ability to write "glue code" pays off. Claude Code is perfect for this because it can handle the heavy lifting of API authentication, JSON/XML parsing, and graph construction without requiring you to be a full-stack engineer.

1. Fetching the Metadata

First, we need a script to extract the data. For Salesforce, we want to query the Tooling API. Using JSforce and Claude Code, we can build a script that handles the 2,000-record limit by iterating through our custom fields.

Claude Code Command:

"Create a Node.js script using JSforce to query MetadataComponentDependency. It should loop through all 'CustomField' types, handle the 2k record limit by chunking, and save the output to sf_map.json."

2. Parsing the Graph

Once you have the raw data—whether it’s a directory of Salesforce XML files from the Metadata API or a massive HubSpot workflow JSON dump—you need a parser.

If you're auditing HubSpot, you're looking for every instance of a property’s internal name. Here’s a logic snippet Claude might generate to search your local JSON exports:

const fs = require('fs');

// Scan all workflow files for a specific property reference
const findFieldUsage = (propertyName, workflowDir) => {
  const files = fs.readdirSync(workflowDir);
  return files.map(file => {
    const flow = JSON.parse(fs.readFileSync(`${workflowDir}/${file}`, 'utf8'));
    const flowStr = JSON.stringify(flow);
    if (flowStr.includes(propertyName)) {
      return { flowId: flow.id, name: flow.name, type: 'Workflow' };
    }
    return null;
  }).filter(Boolean);
};

3. Scoring the Blast Radius

With the dependency map built, you can categorize fields by risk. I use a three-tier heuristic to guide my team:

  • Tier 1: High Risk (Structural). The field is referenced in Apex code, Triggers, or active Flow logic. Deleting this will cause a deployment failure or an unhandled exception in production.
  • Tier 2: Moderate Risk (Functional). The field is used in Reports, Dashboards, or List filters. Deletion won't break the system, but it will break someone’s visibility.
  • Tier 3: Low Risk (Orphaned). Zero references found in the metadata scan.

The "False Positive" Trap

Static metadata analysis has limits. Before you delete a Tier 3 field, you must check for dynamic references that don't live in the CRM metadata:

  1. BI and Data Warehouses: Tools like Fivetran or Snowflake pull data via the API. If your Tableau dashboard relies on a field, the CRM metadata won't know.
  2. External Webhooks: If a custom middleware (Workato, Zapier) or a legacy Node.js app is hitting a field via the API, it won't show up in the Tooling API map.
  3. Third-Party Managed Packages: Salesforce often hides dependencies inside protected managed packages.

The Verification Script: Use Claude to write a secondary script that checks the EventLogFile (Salesforce) or Property History (HubSpot) for the last 90 days. If a field has zero metadata references and has not been updated or read by an API user in three months, it’s truly safe to decommission.

A Repeatable Deprecation Workflow

Don't just delete. Use this technical audit as the foundation for a safe sprint:

  1. Soft Deprecation: Use the Metadata API to rename the field (e.g., z_DEPRECATED_Field__c) and remove it from all page layouts. This forces "human" dependencies to surface without breaking logic.
  2. Field Hiding: Use Permission Sets to remove read/write access for everyone except the System Admin.
  3. Hard Deprecation: After 30 days of silence, run your Claude-built analyzer one last time to ensure no new dependencies were introduced, then delete the field in a Sandbox, run all tests, and deploy the deletion to Production.

Build vs. Buy

Yes, you can buy Salto or Elements.cloud. For enterprise orgs with 5,000+ fields and a dedicated budget, those are excellent choices. They provide a persistent governance layer that a custom script can’t.

But for many operators, the hurdle isn't the technology—it's the procurement cycle. Using Claude Code to build a custom dependency analyzer allows you to start cleaning your schema today. It turns a month of manual "clicking around" into an afternoon of engineering, giving you the technical confidence to prove exactly why a field is safe to kill.

— C.B.