Audit Salesforce lead distribution using Claude Cowork

low complexityCost: Usage-based

Prerequisites

Prerequisites
  • Claude Desktop with Cowork enabled
  • Salesforce instance URL and access token
  • Slack channel ID or incoming webhook URL
  • A computer that stays awake during business hours

Overview

Claude Cowork lets you schedule a recurring audit of lead distribution across your sales team. Instead of assigning leads in real time, this approach runs periodically to identify imbalances — reps who are overloaded, reps with no recent assignments, or leads that fell through the cracks — and posts a report to Slack.

Step 1: Create the Cowork task

Open Claude Desktop and go to the Cowork tab. Click + New task.

Title: Audit Salesforce lead distribution

Description:

You are a sales ops assistant. Audit the distribution of recently created leads across sales reps and post a report to Slack.
 
Steps:
1. Query Salesforce for leads created in the last 7 days, grouped by owner.
   GET https://YOUR_INSTANCE.my.salesforce.com/services/data/v59.0/query?q=SELECT+OwnerId,Owner.Name,COUNT(Id)+lead_count+FROM+Lead+WHERE+CreatedDate=LAST_N_DAYS:7+GROUP+BY+OwnerId,Owner.Name+ORDER+BY+COUNT(Id)+DESC
   Auth: Bearer token — use the SALESFORCE_ACCESS_TOKEN environment variable.
 
2. Calculate distribution stats:
   - Total leads assigned
   - Average leads per rep
   - Highest and lowest rep counts
   - Standard deviation (if significant imbalance)
 
3. Flag any imbalances:
   - Reps with 2x or more the average count
   - Reps with zero leads in the past week
   - Unowned leads (OwnerId matches a queue, not a person)
 
4. Post the audit report to Slack using SLACK_BOT_TOKEN and SLACK_CHANNEL_ID environment variables.
 
5. Print a summary of the distribution.
 
Important: This is a read-only audit. Do not reassign any leads unless explicitly told to.

Replace YOUR_INSTANCE with your actual Salesforce instance URL.

Use environment variables for credentials

Store your Salesforce access token as SALESFORCE_ACCESS_TOKEN and Slack bot token as SLACK_BOT_TOKEN as shell environment variables. Claude can read them when running bash commands.

Step 2: Set the schedule

Frequency: Daily at 9:00 AM (or weekly on Mondays for lower-volume teams)

Step 3: Run manually first

Click Run now to test. A successful run looks like:

Queried Salesforce for leads created in the last 7 days. Found 47 leads across 5 reps.
 
📊 Lead Distribution Audit — Last 7 Days
 
Sarah Chen: 14 leads (⚠️ above average)
Mike Johnson: 12 leads
Lisa Park: 10 leads
David Kim: 8 leads
Alex Rivera: 3 leads (⚠️ below average)
 
Average: 9.4 leads/rep
Imbalance detected: Sarah has 4.7x more leads than Alex.
 
Posted audit report to Slack.
Cowork requires Claude Desktop to be running

Scheduled tasks only run while Claude Desktop is open and your computer is awake. For daily audits that must run reliably, use the Agent Skill with cron instead.

When to use this approach

  • You want visibility into lead distribution without changing assignments
  • You're evaluating whether your current routing is fair before building automation
  • You want a quick daily check that takes zero code to set up
  • You want to combine the audit with other daily reports in a single Cowork task

When to switch approaches

  • You want real-time round-robin assignment → use n8n or Salesforce Flow Builder
  • You need the audit to run every day including weekends → use the Agent Skill with cron
  • You want to automatically rebalance leads, not just report → modify the Agent Skill to include reassignment logic

Need help implementing this?

We build and optimize automation systems for mid-market businesses. Let's discuss the right approach for your team.