← Templates / Support 8 min read

How to Triage Support Emails into Salesforce Cases on Codiedev

An agent checks every support email for the facts a case needs, asks the sender for what's missing or drafts a Salesforce Case, and a person approves before anything is sent or created.

View the repo ↗
Time to tryAbout 5 minutes
Time per emailAbout 5 seconds
You needA Codiedev account
Tested onSalesforce Developer Edition

A support inbox fills up with emails that can't become a case yet. One doesn't say which site it's about. Another doesn't say when the problem started, or who's affected. Someone has to write back and ask, then copy everything into Salesforce once the answer arrives.

This template does that first pass. An agent reads each email and checks it for the facts a case needs. If any are missing, it drafts a reply asking only for those. If the email has everything, it drafts a Salesforce Case. Either way, a person approves the draft before anything is sent or created.

It starts with a fake Salesforce, so you can try the whole loop with nothing but a Codiedev account. Switch to your real org when the drafts look right.

What you're building

New emailFrom your mail system's webhook
→
Check the factsEach one quoted from the email, or counted missing
→
Person approvesEdit the reply or the Case fields, then decide
→
Reply sent or Case createdPlus a note saying who approved it

For each email the agent:

  1. masks card and phone numbers before anything reaches a model
  2. pulls out each required fact (by default: site ID, when it started, who or what is affected), and the model has to quote the words that state it
  3. throws out any fact whose quote isn't actually in the email, so a missing fact is never guessed
  4. drafts a reply asking for the missing facts, or a Case with subject, description, priority and site ID
  5. asks a person in Codiedev, with the draft in editable fields
  6. sends the approved reply or creates the Case, and does it exactly once even if the run is retried

What you need

  • A Codiedev account with Agents on. Any model your company allows works; we used the default, GLM 5.3 Flash.
  • Claude Code, Codex, Cursor or another coding agent, with the Codiedev CLI installed (npm i -g codiedev@latest). Each step below is a prompt for your coding agent, followed by the commands if you'd rather run them yourself.

Step 1: Get the template and try it

Say this to Claude Code (or any coding agent)
Set up the Codiedev email triage template from
github.com/Signal-and-Code/email-triage-salesforce-template in ./email-triage.
Read its README and AGENTS.md, create a .venv with the openai package, then run
the three sample emails locally and show me what it decided for each one.
Or run it yourself
git clone https://github.com/Signal-and-Code/email-triage-salesforce-template email-triage
cd email-triage && cp .env.example .env
python3 -m venv .venv && .venv/bin/pip install openai
codiedev agents run --local --input-file samples/missing-site-id.json

Step 2: Read the decisions

The three samples test the three outcomes:

Sample emailWhat the agent decided
"We're having problems again… ASAP"Ask for all three facts
The network is down on floors 3–5 since 9:30pm last night, about 60 people affected, sent from "the Harbor Point office"Ask only for the site ID. The office name isn't a site ID
Site 40217, guest Wi-Fi portal down since 6:15am, every meeting room and the lobbyDraft a High-priority Case

We ran each sample four times and got the same decision every time. Here's the second one:

Output
<sample-0002.missing-site@example.org>: facts {"site_id": null, "started": "about 9:30pm last night
  (Sunday, Nov 29)", "affected": "About 60 people on floors 3, 4 and 5, wired and Wi-Fi"} · missing ['site_id']
[salesforce_fake] note on <sample-0002.missing-site@example.org>: {"text": "Triage: Medium, missing site_id"}
[local] approval requested: Ask m.lee@example.org for the missing site ID? (send, reject);
  not sent on a local run

The drafted reply asks only for what's missing:

Output
Hi Marcus,

Thanks for contacting Northwind Support about "Network down on floors 3-5". So we can open
a case, please reply with:

- Your site ID

Northwind Support

Step 3: Set your own facts

Your support team knows what a case needs. It's one dictionary at the top of agent.py, and the prompt, the reply and the approval card all follow it:

Say this to Claude Code (or any coding agent)
Change the required facts in agent.py to: <your list, e.g. account number, product,
error message, how many users>. Keep the account number as ID_FACT. Update the
priority rules to: <your rules>. Set COMPANY_NAME and SIGNATURE in .env. Then
write three sample emails like ours in samples/ and run each locally.

The tests/ folder checks the fact rules offline (python -m unittest discover tests), so you can change them without guessing.

Step 4: Deploy it and approve one

Say this to Claude Code (or any coding agent)
Deploy the email triage agent to Codiedev, run it on samples/complete.json,
and show me the approval waiting for me.
Or run it yourself
codiedev agents deploy
codiedev agents run email-triage --input-file samples/complete.json
codiedev agents approvals

In Agents → Approvals, the approver sees the email, the facts the agent found, and the Case fields in editable boxes. They can fix anything, then click create or reject. From the terminal, the fields start with the drafted values and --value changes one:

Or run it yourself
codiedev agents decide <approval-id> create --value priority=Medium

The decision starts a second, short run:

Output
[salesforce_fake] case on <sample-0003.complete@example.net>: {"case_id": "500FAKE00000000001",
  "case_number": "00000001"}
[salesforce_fake] note on <sample-0003.complete@example.net>: {"text": "Case 00000001 created;
  approved by you@yourcompany.com with edits."}

Nothing runs while a draft waits, so leaving it overnight costs nothing. Drafts nobody decides on expire after 7 days and leave a note.

Step 5: Connect Salesforce

The template ships the Salesforce side as metadata in salesforce-setup/:

  • two Case fields, a site ID and a unique External ID
  • a permission set
  • an External Client App with the client credentials flow

Then pick how the agent reaches it:

How it reaches SalesforceYour company's connector (recommended)Direct
Salesforce secrets in the agentNone. Codiedev's MCP gateway holds themThe consumer key and secret
What it may writeOnly what your admins allow, such as Case and CaseCommentWhatever the run-as user can
Audit and pauseEvery call in MCP Controls, and an admin can pause the agentSalesforce's own logs

With your company's connector

Deploy the metadata below, then hand the consumer key and secret to whoever installs your Salesforce connector instead of giving them to the agent. An admin allows writes to Case and CaseComment in MCP Controls → Connectors → Salesforce → Policy, and the agent's owner gives it the connector on its Tools tab. Then:

Or run it yourself
codiedev agents secrets email-triage set SALESFORCE=connector SF_ID_FIELD=Site_ID__c SF_EXTERNAL_ID_FIELD=Email_Key__c

The connector has no upsert, so the agent looks the Case up by its email key first and updates it when found. We tested this through Codiedev's hosted gateway against a Developer Edition org: the history lookup, the Case and its private comment.

Direct

Your coding agent can deploy it with the Salesforce CLI:

Say this to Claude Code (or any coding agent)
Connect my email triage agent to our Salesforce sandbox. In salesforce-setup/, set
the contact email to <me> and the run-as user to <our integration user>, deploy it
with the sf CLI, and assign the Email_Triage_Agent permission set to that user. Then
tell me where to copy the consumer key and secret, set the agent's SF_* secrets
(never in code), send samples/complete.json through, and show me the Case after I
approve it.
Or run it yourself
cd salesforce-setup && sf project deploy start --target-org <your org>
sf org assign permset --name Email_Triage_Agent --on-behalf-of <integration user> --target-org <your org>
codiedev agents secrets email-triage set SALESFORCE=live \
  SF_INSTANCE_URL=https://your-domain.my.salesforce.com SF_CLIENT_ID=… SF_CLIENT_SECRET=… \
  SF_ID_FIELD=Site_ID__c SF_EXTERNAL_ID_FIELD=Email_Key__c

The consumer secret is the one value you copy by hand. Find it under External Client App Manager → Email Triage Agent → Settings → OAuth Settings → Consumer Key and Secret.

Here's what our run against a Salesforce Developer Edition org printed after we approved with priority changed to High:

Output
[salesforce] case on <sample-0003.complete@example.net>: {"case_id": "500g700002dQDWnAAO",
  "case_number": "00001026"}
[salesforce] note on <sample-0003.complete@example.net>: {"text": "Case 00001026 created;
  approved by you@yourcompany.com with edits.", "on_case": "500g700002dQDWnAAO"}

In Salesforce, Case 00001026 has priority High, origin Email, site ID 40217 and the sender's address. The note is a private Case comment.

  • No duplicates. The Case is upserted by a key from the email's Message-ID. We sent the same email through again and approved it, and it updated Case 00001026 instead of creating a second Case.
  • Least access. Use a dedicated integration user as the run-as user, with only the permission set.
  • No Salesforce MCP add-on either way. The connector and the direct mode both call the Salesforce REST API.

Step 6: Connect your inbox

Say this to Claude Code (or any coding agent)
Give my email triage agent a shared secret and a webhook, then help me build a
<Power Automate | Microsoft Graph | Gmail> flow that posts each new email in our
support mailbox to it, and a second flow that sends the approved replies it posts
to REPLY_WEBHOOK_URL.
Or run it yourself
codiedev agents secrets email-triage set SHARED_SECRET=$(openssl rand -hex 16)
codiedev agents webhook email-triage

Each new email is a POST to the webhook with the X-Shared-Secret header and this body:

JSON
{"email": {"message_id": "<the Message-ID header>", "from": "Name <addr>", "subject": "…", "body": "plain text"}}

Approved replies go out the same way in reverse. The agent POSTs {to, subject, body, in_reply_to} to REPLY_WEBHOOK_URL with an Idempotency-Key header, and your flow sends it in the original thread. Start with a test mailbox.

How the approval works

The Case path is one call. The run asks, then ends, and a new run starts when someone decides:

Code
approval = agents.request_approval(
    f"Create a Salesforce Case for site ID {facts['site_id']}? ({priority})",
    details=approval_details(ticket, facts, extracted, history, "case"),
    options=["create", "reject"],
    fields=[
        {"name": "subject", "type": "text", "label": "Subject", "default": draft["subject"], "required": True},
        {"name": "description", "type": "textarea", "label": "Description", "default": draft["description"], "required": True},
        {"name": "priority", "type": "select", "label": "Priority", "options": PRIORITIES, "default": priority, "required": True},
        {"name": "site_id", "type": "text", "label": "Site ID", "default": draft["site_id"], "required": True},
    ],
    context={"kind": "case", "ticket": ticket, "case": draft},
)

The next run gets the decision and whatever was in the boxes when the approver clicked. Creating the Case is wrapped in agents.step(), so a retried run returns the first result instead of creating another Case.

A note on customer data

Email text goes to a model, so it shows up in the agent's traces in Codiedev. redact() in agent.py masks card and phone numbers first. Add anything else you don't want stored, such as account numbers or addresses. Check a few traces after your first real emails.

Where to take it next

  • Learn from edits. Every edit an approver makes is a correction. Turn those into test cases with codiedev traces cases so you can tell whether a prompt or model change helped.
  • Close the loop. When the sender answers with the missing facts, send the reply back through the same webhook, quoting the original, so the agent sees everything and drafts the Case.
  • One agent per environment. Deploy email-triage-dev and email-triage-prod from the same folder, each with its own secrets, budget and approvers.

If you get stuck, reach out to support in the portal and we'll help you set it up.

Build it on Codiedev

Build your own agent next.

Start from this template or from scratch. Models, sandboxes, approvals and traces are built in, so you describe the agent to your coding agent and Codiedev runs it.

Request a demo