trigger

A command guide for Salesforce triggers, which are pieces of code that run when records change. It supports creating, reviewing, refining, or fixing a trigger and its handler class.

In plain words
What is it for?
Creating trigger, handler, and test classes; reviewing existing implementations; changing event logic; and diagnosing trigger bugs.
Why use it?
It provides a repeatable way to gather requirements, check for conflicting triggers, and keep business logic organized and tested.

Command

Part of the sfdx-iq plugin — 20 commands, 7 agents shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/bhanu91221/sfdx-iq/trigger
Clone the repo
git clone --depth 1 https://github.com/bhanu91221/sfdx-iq

Or install sfdx-iq, the plugin that ships this one along with the rest of its 20 commands, 7 agents.

Per session 14 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,001 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00014 $0.02001
Opus 5 $0.00007 $0.01001
Sonnet 5 $0.00003 $0.00400
Haiku 4.5 $0.00001 $0.00200

Measured 2d ago against content hash c8eee276119d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

trigger scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/trigger.md · 232 lines

How it starts

The opening of the file, as written. The whole thing — 232 lines — stays where its author put it; the contents beside it link to each section on GitHub.

/trigger

Work with Salesforce triggers and trigger handler classes using --new, --review, --refine, or --bug-fix.

Usage

/trigger --new          Create a new trigger + handler + test class
/trigger --review       Review an existing trigger/handler for quality and patterns
/trigger --refine       Modify a trigger or handler (add event context, change logic)
/trigger --bug-fix      Diagnose and fix a bug in a trigger or handler

--new: Create a New Trigger + Handler

Gather Requirements

Ask the user:

  1. Which SObject? (e.g., Account, Custom_Object__c)
  2. Which trigger events? (before insert, before update, before delete, after insert, after update, after delete, after undelete — default: all seven)
  3. What business logic should the handler implement? (brief description per event)
  4. Does a trigger already exist on this object? (warn if yes — one trigger per object)
  5. Use a TriggerHandler framework base class? (if the project has one, detect it)

Check for Existing Triggers

Glob: force-app/**/triggers/<ObjectName>Trigger.trigger

If found: warn the user about the one-trigger-per-object rule. Offer to add logic to the existing trigger or stop.

Trigger Standards (baked in)

One Trigger Per Object:

  • ONLY ONE trigger per SObject — ever
  • All logic belongs in the handler class, not in the trigger body
  • The trigger body is a single dispatcher call

Trigger Pattern:

// AccountTrigger.trigger — NO logic here
trigger AccountTrigger on Account (
    before insert, before update, before delete,
    after insert, after update, after delete, after undelete
) {
    new AccountTriggerHandler().run();
}

Handler Class Pattern:

public with sharing class AccountTriggerHandler {

    // Recursion prevention
    private static Boolean isRunning = false;

    public void run() {
        if (isRunning) return;
        isRunning = true;
        try {
            if (Trigger.isBefore) {
                if (Trigger.isInsert)  beforeInsert(Trigger.new);
                if (Trigger.isUpdate)  beforeUpdate(Trigger.new, Trigger.oldMap);
                if (Trigger.isDelete)  beforeDelete(Trigger.old);
            }
            if (Trigger.isAfter) {
                if (Trigger.isInsert)  afterInsert(Trigger.new);
                if (Trigger.isUpdate)  afterUpdate(Trigger.new, Trigger.oldMap);
                if (Trigger.isDelete)  afterDelete(Trigger.old);
                if (Trigger.isUndelete) afterUndelete(Trigger.new);
            }
        } finally {
            isRunning = false;
        }
    }

    private void beforeInsert(List<Account> newRecords) {
        // Delegate to service or domain class
        AccountDomain.setDefaultIndustry(newRecords);
    }

    private void afterInsert(List<Account> newRecords) {
        // Collect changed records and delegate
        AccountService.syncToExternalSystem(new Map<Id, Account>(newRecords).keySet());
    }

    private void beforeUpdate(List<Account> newRecords, Map<Id, Account> oldMap) { }
    private void afterUpdate(List<Account> newRecords, Map<Id, Account> oldMap) { }
    private void beforeDelete(List<Account> oldRecords) { }
    private void afterDelete(List<Account> oldRecords) { }
    private void afterUndelete(List<Account> newRecords) { }
}

Read the full file on GitHub · 232 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 232 lines · 14 tokens per session scan A c8eee276119d

Subscribe to this mod's changes

trigger is a command published in the GitHub repository bhanu91221/sfdx-iq (2 stars, last pushed 3mo ago), licensed MIT. It adds 14 tokens to every session and 2,001 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.