Sam opened the session saying his Salesforce was a mess and asked for a full audit of folders and sheets in the Projects directory to identify what analyses had been done and what was pending execution. He wanted those pending items cross-referenced with live Salesforce and Litify, then walked through one by one so we could create a dedicated folder for each project that would include files, instructions, and resources an autonomous agent would need to execute the cleanup perfectly with rollback.
The goal evolved during the session. After identifying 14 pending items from prior session summaries, Sam caught a category error in a previous agent's 2026-04-13 cleanup that had moved 22 intakes from Referred Out to Turned Down. Those statuses are mutually exclusive terminal states (if we referred it, it's referred; we don't also turn down our own referrals). This added a 15th project (P03 rollback) and two new sibling projects (P14 referral outcome model, P15 intake status picklist consolidation). Sam then asked for the top 3 fast scaffolds to be completed in-session plus three execution handoffs dividing the remaining work and a fourth handoff deploying a conductor agent plus team of subagents to run the executions.
A new top-level folder was created at /Users/samaguiar/Documents/Projects/Salesforce-Cleanup-Projects/ with 8 fully-scaffolded project folders plus a _handoffs/ subfolder containing 4 handoff documents.
Each scaffolded project folder follows this exact structure so an agent can be pointed at the folder and told "read INSTRUCTIONS.md and execute":
PXX-short-name/
README.md mission, live-verified state, exit criteria, risk
INSTRUCTIONS.md cold-start agent-executable step-by-step
context/ source memos, handoff notes, input CSVs
scripts/ Apex / JS / Python the agent will run
metadata/ Salesforce DX metadata (field XML, VR XML, etc.)
backups/ pre-execution snapshots (populated at execution)
rollback/ written rollback procedure + restore scripts
logs/ execution logs (populated at execution)
Every script includes explicit safety pre-checks that halt on any drift between the scaffold's assumed state and live Salesforce state. Every project has a full rollback procedure. Every project ends with an OPS_LEDGER entry template so the agent closes the loop.
P02 — Insurance company dedup finish. Carries forward from a prior session that completed 295 name-normalized merges. 1,410 distinct insurance-company accounts remain. Four invalid Salesforce Ids in Sam's original actual duplicates list need correcting; 92 address-based merge pairs were staged but never executed. Scaffold includes Apex merge pattern at up to 25 pairs per transaction with backup-before-each-batch and spot-check halts. scripts/dump-xlsx-to-csv.py dumps the source xlsx so Ids can be validated. Highest risk project of the set because Account merges are near-irreversible; rollback doc spells this out.
P03 — Rollback the 2026-04-13 Referred Out -> Turned Down bulk update. This is the rollback of the category error Sam caught. The 22 target Ids are listed in context/ky-auto-referred-declined-status-update-2026-04-13.csv (preserved from the original cleanup). Script rollback-status.apex reads current state, halts if any Id is not currently Turned Down, snapshots a pre-rollback backup, then batch-updates all 22 back to Referred Out. Forward-rollback Apex preserved in case the rollback itself needs reversing. Very low risk, fully reversible.
P09 — Damages display fields on Matter. The managed-package Litify fields litify_pm__Total_Damages__c and litify_pm__lit_Damage_Total__c can't be renamed. Scaffold creates two Currency formula fields on Matter: Total_Billed__c (aliases the Damages total) and Total_Due__c (aliases the net-due total). Includes DX metadata in metadata/phase1-fields/ ready for sf project deploy start. Very low risk; rollback is delete-the-fields.
P10 — Require_Topic validation rule fix on litify_pm__lit_Note__c. The VR was disabled 2026-04-13 because a Task-triggered flow was creating Litify Notes without Topic. Live-check reveals 4,997 new null-Topic notes in the last 30 days by real users, so the root cause is still not fixed. 232,751 historical null-Topic notes exist. Scaffolded as staged execution: (1) discover exact flow API name via metadata retrieve, (2) fix flow to set Topic to 'Phone Call' on create, (3) wait 24 hours and monitor, (4) deploy refined VR with formula AND(OR(ISNEW(), ISCHANGED(Topic)), ISBLANK(TEXT(Topic))) so historical null-Topic notes stay editable.
P11 — Appointment confirmation email (Intake). Auto-populate email fields when Scheduled_Intake_Date_Time__c changes; user clicks Send Confirmation quick action to open prefilled composer. Scaffold includes 3 new fields, a record-triggered flow, a quick action, a training note. Halts at Step 2 for Sam's Decision A (recipient source) and Decision B (auto-stamp a Sent timestamp).
P13 — Topic picklist migration closeout. Live-check revealed the migration already completed: 0 records on all 22 retired values. Project becomes a lightweight closeout: verify zero records, attempt metadata deploy to deactivate retired values (likely fails due to managed namespace), fall back to Setup UI to mark Inactive, update OPS_LEDGER.
P14 — Referral outcome model. Lets referred-out intakes keep their Referred Out status while tracking the outside firm's outcome separately on the Referral record. Research discovered litify_pm__Referral__c.Referral_Status__c already exists and is 99.76% adopted on Referred Out intakes (2,896 of 2,903). Gap: no Decline Reason field. Scaffold adds two new fields, a VR that requires Decline Reason when status = Declined, a historical backfill script that sets 2,097 existing Declined referrals to 'Historical — reason not captured' before activating the VR, a 7-record null-status backfill (halts for Sam's review), layout placement, and a new report titled 'Referred Out Intakes by Referral Outcome'. Also surfaces a 1,571-intake gap: Referred Out intakes with NO referral record at all.
P15 — Intake Status picklist consolidation. Reduces litify_pm__Intake__c.litify_pm__Status__c from 11 active values to 8. Per Sam's in-session guidance: KEEP Retainer Agreement Sent + Signed (both are workflow triggers), DEPRECATE Under Review -> Working, Post-Retainer Review -> Retainer Agreement Signed, Disengaged After Retainer -> Lost. Research also answered Open vs Working: keep both because Open = system-created not yet claimed, Working = claimed by a human. Scaffold includes remap-9-intakes.apex, cleanup-stuck-2021-working.apex for 7 stuck 2021-2023 Working intakes with 12-month safety guard, metadata XML for picklist deactivation, and a VR VR_Intake_Prevent_Terminal_Reopen that blocks backward transitions from terminal statuses back to active ones.
Handoff A — Data cleanup track (P01 + P04). Phone standardization finish (11,600 Contact + 425 Account failures + two before-save auto-format flows) and Task Automation Phase 1 finish (verify 9 deployed fields, resolve Update Referring Attorney task, build Intake->Matter field sync). 4-6 hours.
Handoff B — Schema/metadata track (P06 + P07). Page layout simplification (5 layouts, clone-first pilot pattern) and low field fill rate cleanup (269 fields under 10% fill; audit script exists but source CSV never loaded). 6-10 hours.