<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ApexCraft Studio</title>
    <description>The latest articles on DEV Community by ApexCraft Studio (@apexcraftstudio).</description>
    <link>https://dev.to/apexcraftstudio</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4247019%2Fd3d0bfd3-7f2c-4ee0-874a-824d8629e658.png</url>
      <title>DEV Community: ApexCraft Studio</title>
      <link>https://dev.to/apexcraftstudio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/apexcraftstudio"/>
    <language>en</language>
    <item>
      <title>Why Your 'Run Once' Trigger Guard Silently Skips Records</title>
      <dc:creator>ApexCraft Studio</dc:creator>
      <pubDate>Mon, 16 Nov 2026 23:59:56 +0000</pubDate>
      <link>https://dev.to/apexcraftstudio/why-your-run-once-trigger-guard-silently-skips-records-1hee</link>
      <guid>https://dev.to/apexcraftstudio/why-your-run-once-trigger-guard-silently-skips-records-1hee</guid>
      <description>&lt;p&gt;If your trigger handler uses a static boolean to "run once", it is probably skipping records in production, and nothing tells you. No error, no failed test, just records that never got processed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pattern everyone copies
&lt;/h2&gt;

&lt;p&gt;Search for "Apex trigger recursion" and you'll find this in almost every tutorial:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apex"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AccountTriggerHandler&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt; &lt;span class="n"&gt;hasRun&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;beforeInsert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hasRun&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;hasRun&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Processed'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The idea is sound: if the trigger updates records and that update fires the trigger again, stop the loop. The static variable lives for the whole transaction, so the second run sees &lt;code&gt;hasRun = true&lt;/code&gt; and exits.&lt;/p&gt;

&lt;p&gt;The problem is that "the second run" isn't always recursion.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually happens: 200-record chunks
&lt;/h2&gt;

&lt;p&gt;Salesforce never hands a trigger more than 200 records at once. When a single DML statement touches more than 200 records, the platform splits them into chunks of 200 and runs your trigger once per chunk, &lt;strong&gt;all inside the same transaction&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So when Apex inserts 1,000 Accounts in one statement:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Chunk&lt;/th&gt;
&lt;th&gt;Records&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;hasRun&lt;/code&gt; before&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1–200&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;Processed, then &lt;code&gt;hasRun = true&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;201–400&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Skipped&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;401–600&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Skipped&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;601–800&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Skipped&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;801–1,000&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Skipped&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Static variables survive across chunks because it's one transaction. The guard can't tell "the same trigger firing again because of recursion" from "the next 200 records". 800 of the 1,000 Accounts never get their Description set, and the insert still succeeds.&lt;/p&gt;

&lt;p&gt;This bites hardest in exactly the places nobody watches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Batch Apex&lt;/strong&gt; with a scope above 200, e.g. &lt;code&gt;Database.executeBatch(job, 2000)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data migration scripts&lt;/strong&gt; run from Anonymous Apex&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Service classes&lt;/strong&gt; that build a list and insert or update it in one call&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flows&lt;/strong&gt; that create or update many records in one element&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everyday testing in the UI saves one record at a time, so it never shows up there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reproduce it in one test
&lt;/h2&gt;

&lt;p&gt;You only need 201 records to see the bug: one full chunk plus one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apex"&gt;&lt;code&gt;&lt;span class="nd"&gt;@IsTest&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AccountTriggerHandler_Test&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@IsTest&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;processesEveryRecordInBulk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;201&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Bulk '&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nc"&gt;Test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startTest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;insert&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// one DML statement, two chunks&lt;/span&gt;
        &lt;span class="nc"&gt;Test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stopTest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kt"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;processed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="no"&gt;SELECT&lt;/span&gt; &lt;span class="no"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="no"&gt;FROM&lt;/span&gt; &lt;span class="nc"&gt;Account&lt;/span&gt; &lt;span class="no"&gt;WHERE&lt;/span&gt; &lt;span class="nc"&gt;Description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Processed'&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;areEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;201&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;processed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Every record should be processed'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the &lt;code&gt;hasRun&lt;/code&gt; guard, this fails with &lt;strong&gt;expected 201, actual 200&lt;/strong&gt;. Record 201 is skipped.&lt;/p&gt;

&lt;p&gt;If your handler tests only insert one or five records, they pass, and the bug ships. Always test triggers with &lt;strong&gt;more than 200 records&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: track record Ids, not a boolean
&lt;/h2&gt;

&lt;p&gt;The real question isn't "has this trigger run?" It's "has &lt;em&gt;this record&lt;/em&gt; already been handled?" Answer that with a &lt;code&gt;Set&amp;lt;Id&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apex"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AccountTriggerHandler&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;processedIds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;afterUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;toProcess&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Set.add returns false if the Id was already there&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;processedIds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;toProcess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;toProcess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="c1"&gt;// ... work on toProcess only&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now chunk 2 brings 200 &lt;em&gt;new&lt;/em&gt; Ids, so they all get processed. A true recursive update brings back Ids that are already in the set, so they're skipped. The guard finally does what it was meant to do.&lt;/p&gt;

&lt;p&gt;A few details matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use it in update contexts.&lt;/strong&gt; Records in &lt;code&gt;before insert&lt;/code&gt; don't have Ids yet. Recursion almost always comes from an after-trigger updating the same records, so guard &lt;code&gt;afterUpdate&lt;/code&gt; (and &lt;code&gt;beforeUpdate&lt;/code&gt; if needed), not inserts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep one set per event&lt;/strong&gt; if a handler runs work in both &lt;code&gt;beforeUpdate&lt;/code&gt; and &lt;code&gt;afterUpdate&lt;/code&gt;, so one doesn't block the other. A &lt;code&gt;Map&amp;lt;String, Set&amp;lt;Id&amp;gt;&amp;gt;&lt;/code&gt; keyed by the trigger operation handles this.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Know the trade-off.&lt;/strong&gt; A record updated twice in one transaction on purpose, e.g. by two different processes, is only handled once. That's usually what you want, but be aware of it. The same goes for partial-success saves (Database.update(records, false), Data Loader, the API): when some records fail, Salesforce retries the rest without resetting static variables, so the set skips them. For logic that's safe to repeat, the next section's approach avoids this entirely.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Even better: only act on records that changed
&lt;/h2&gt;

&lt;p&gt;Often you don't need a recursion guard at all. Most recursion happens because a handler reacts to &lt;em&gt;every&lt;/em&gt; update, including the one it just made itself. Compare against &lt;code&gt;Trigger.oldMap&lt;/code&gt; and react only to the change you care about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apex"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;afterUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;oldMap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ratingChanged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rating&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;oldMap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rating&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;ratingChanged&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// ... work on ratingChanged only&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your own follow-up update doesn't change &lt;code&gt;Rating&lt;/code&gt; again, the second run finds nothing to do and stops by itself.&lt;/p&gt;

&lt;p&gt;The same goes for the &lt;code&gt;beforeInsert&lt;/code&gt; example at the top. A before-insert handler that only sets fields on &lt;code&gt;Trigger.new&lt;/code&gt; can't cause recursion, because it doesn't run any DML. &lt;strong&gt;It needs no guard at all.&lt;/strong&gt; Delete the &lt;code&gt;hasRun&lt;/code&gt; check and all 201 records pass the test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist for your triggers
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Search your org for &lt;code&gt;static Boolean&lt;/code&gt; in trigger handlers. Each one is a candidate for this bug.&lt;/li&gt;
&lt;li&gt;Remove guards from handlers that don't run DML on the same object.&lt;/li&gt;
&lt;li&gt;React to field changes with &lt;code&gt;Trigger.oldMap&lt;/code&gt; instead of every update.&lt;/li&gt;
&lt;li&gt;Where you still need a guard, track a &lt;code&gt;Set&amp;lt;Id&amp;gt;&lt;/code&gt;, not a boolean.&lt;/li&gt;
&lt;li&gt;Test every trigger with &lt;strong&gt;201+ records&lt;/strong&gt; in a single DML statement.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Want this already built?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;ApexCraft Apex + LWC Starter Kit&lt;/strong&gt; includes a trigger framework with this Id-based guard built in, plus a bypass API, an admin on/off switch, service and selector layers, a rollback-safe logger and six Lightning Web Components. It deploys in one command, with 68 Apex tests and 45 Jest tests included.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apexcraftstudio.gumroad.com/l/starter-kit/LAUNCH10" rel="noopener noreferrer"&gt;Get the Starter Kit →&lt;/a&gt; ($19 launch price until December 16)&lt;/p&gt;

&lt;p&gt;Either way, go check your handlers for that &lt;code&gt;static Boolean&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Follow-up:&lt;/em&gt; &lt;a href="https://dev.to/apexcraftstudio/7-bugs-that-passed-100-tests-in-my-salesforce-starter-kit-bm1"&gt;7 bugs that passed 100+ tests in my Salesforce starter kit&lt;/a&gt; covers the retry trap and six more.&lt;/p&gt;

</description>
      <category>salesforce</category>
      <category>apex</category>
      <category>programming</category>
      <category>testing</category>
    </item>
    <item>
      <title>7 bugs that passed 100+ tests in my Salesforce starter kit</title>
      <dc:creator>ApexCraft Studio</dc:creator>
      <pubDate>Mon, 16 Nov 2026 23:49:54 +0000</pubDate>
      <link>https://dev.to/apexcraftstudio/7-bugs-that-passed-100-tests-in-my-salesforce-starter-kit-bm1</link>
      <guid>https://dev.to/apexcraftstudio/7-bugs-that-passed-100-tests-in-my-salesforce-starter-kit-bm1</guid>
      <description>&lt;p&gt;My Salesforce starter kit had 113 passing tests: 68 Apex, 45 Jest. It deployed cleanly to a real org. Then a tester clicked through the data table, and a fresh-eyes review read every class. Together they found seven real bugs, and not one test had failed.&lt;/p&gt;

&lt;p&gt;None of these bugs is exotic. Each one hides in a gap between what a test checks and what a real org does. Here they are, with the fix for each, so you can check your own code for the same traps.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Page 4 showed page 1
&lt;/h2&gt;

&lt;p&gt;The tester sorted 31 Accounts by Annual Revenue and clicked Next three times. The footer said "Page 4 of 4", but the table still showed the top 10 records.&lt;/p&gt;

&lt;p&gt;The server pages with a &lt;strong&gt;keyset cursor&lt;/strong&gt;: "give me rows after the last one you saw", which avoids SOQL's 2,000-row &lt;code&gt;OFFSET&lt;/code&gt; limit. The browser was still running the &lt;em&gt;previous&lt;/em&gt; version of the component, cached by Lightning. That version sent only a page number, never a cursor. With no cursor, the server treated every request as page 1.&lt;/p&gt;

&lt;p&gt;The tests passed because they called each version with the arguments it expected. Nothing tested an old client against the new server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; never quietly return page 1 for a later page. If a request for page 2 or later arrives without a cursor, fall back to offset paging:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apex"&gt;&lt;code&gt;&lt;span class="kt"&gt;Boolean&lt;/span&gt; &lt;span class="n"&gt;keyset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;KEYSET_FIELDS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;containsKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;cursorId&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Check your code:&lt;/strong&gt; when you change an &lt;code&gt;@AuraEnabled&lt;/code&gt; method's contract, ask what an old client would get. Then hard-refresh (Ctrl+Shift+R) before you trust a manual test.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The recursion guard skipped retried records
&lt;/h2&gt;

&lt;p&gt;Most tutorials stop trigger recursion with a static "already ran" flag. That &lt;a href="https://dev.to/apexcraftstudio/why-your-run-once-trigger-guard-silently-skips-records-1hee"&gt;silently skips records 201 and up&lt;/a&gt;, because Salesforce runs triggers in chunks of 200. My guard tracked record &lt;strong&gt;Ids&lt;/strong&gt; instead, and a 201-record test proved it worked.&lt;/p&gt;

&lt;p&gt;But a set of Ids has its own trap. When a save runs with all-or-none off (&lt;code&gt;Database.update(records, false)&lt;/code&gt;, Data Loader, the API) and some records fail, Salesforce rolls back and re-runs the trigger for the records that succeeded. Static variables are &lt;strong&gt;not&lt;/strong&gt; reset. The guard sees those Ids as done and skips them. The records save, but the trigger logic never runs on them, and nothing reports it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; for logic that is safe to repeat, like a roll-up, skip the guard. Compare old and new values, and recalculate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apex"&gt;&lt;code&gt;&lt;span class="kt"&gt;Boolean&lt;/span&gt; &lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Budget__c&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;old&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Budget__c&lt;/span&gt;
    &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Status__c&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;old&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Status__c&lt;/span&gt;
    &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Account__c&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;old&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Account__c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep an Id guard only for work that must happen exactly once, like sending a notification.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Detailed logs vanished without an error
&lt;/h2&gt;

&lt;p&gt;The logger publishes a platform event, and a subscriber trigger saves it as a &lt;code&gt;Log__c&lt;/code&gt; record. Because the event publishes immediately, the log survives even when the transaction rolls back.&lt;/p&gt;

&lt;p&gt;The event's &lt;code&gt;Level__c&lt;/code&gt; field took any &lt;code&gt;LoggingLevel&lt;/code&gt; name. The &lt;code&gt;Log__c&lt;/code&gt; picklist, though, was restricted to ERROR, WARN, INFO and DEBUG. Logging at FINE published the event fine, then the subscriber's insert failed. That failure went to a debug log of the Automated Process user, where nobody looks.&lt;/p&gt;

&lt;p&gt;The tests never logged below DEBUG, so they never noticed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; store anything finer than DEBUG as DEBUG:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apex"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;storedLevel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LoggingLevel&lt;/span&gt; &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;SEVERITY&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;SEVERITY&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LoggingLevel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DEBUG&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'DEBUG'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Check your code:&lt;/strong&gt; for every restricted picklist, find each place that writes to it, and test with a value outside the list.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The example trigger changed real data
&lt;/h2&gt;

&lt;p&gt;The kit shipped an example Account trigger that tidies names and fills a blank Rating with "Warm". It was there to show the framework working.&lt;/p&gt;

&lt;p&gt;It was also active. Anyone who deployed the kit got a trigger that changed their Account data. Worse, their own tests that expected an empty Rating would start failing, which rolls back the deploy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; example code ships switched off. The framework reads an on/off switch from custom metadata, so the record now sets &lt;code&gt;Is_Active__c&lt;/code&gt; to false, and the tests turn the handler on only while they run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apex"&gt;&lt;code&gt;&lt;span class="nc"&gt;TriggerHandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;settingOverrides&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'AccountTriggerHandler'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Check your code:&lt;/strong&gt; if you ship anything to another org, list what changes the moment it's deployed. That list should be empty.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. &lt;code&gt;refresh()&lt;/code&gt; could show stale data
&lt;/h2&gt;

&lt;p&gt;The data table has a public &lt;code&gt;refresh()&lt;/code&gt; method, so a parent component can reload it after saving a record. The Apex method behind it was &lt;code&gt;@AuraEnabled(cacheable=true)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Cacheable methods are stored in the client-side cache. When the component calls one imperatively with the same arguments, it may get the cached answer back instead of fresh data. So right after someone saved a record, "refresh" could show the old rows.&lt;/p&gt;

&lt;p&gt;Jest mocks the Apex call, so no unit test can catch this. It only shows up in a real browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; remove &lt;code&gt;cacheable=true&lt;/code&gt; from methods that must return current data, or use &lt;code&gt;@wire&lt;/code&gt; with &lt;code&gt;refreshApex()&lt;/code&gt;. Keep caching for searches and reference data, where an old answer does no harm.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. The no-CLI install shipped old code
&lt;/h2&gt;

&lt;p&gt;The kit includes a zip for deploying through Workbench, for people without the Salesforce CLI. I'd been testing every fix by deploying the source folder, but nobody rebuilt the zip. Six of its files were an older version, without the last round of fixes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; build the zip from the source folder in one script, compare every file against the source before release, and deploy the zip itself as the final test. That last deploy ran 68 of 68 tests in a real org.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. A huge page number overflowed
&lt;/h2&gt;

&lt;p&gt;Offset paging computed &lt;code&gt;(page - 1) * size&lt;/code&gt; before checking it against the 2,000-row limit. A page number near the Integer maximum overflowed to a negative number before the check could catch it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; compare first, multiply after:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apex"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;maxOffset&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nf"&gt;handled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Sorting by '&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;field&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;' pages through the first 2,000 rows.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The table also stops on the last page it can reach and shows a short note explaining why, instead of failing on the next click.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell myself before shipping
&lt;/h2&gt;

&lt;p&gt;Every bug above lived in a gap the tests couldn't see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Between versions:&lt;/strong&gt; an old client calling a new server (bug 1), and a release zip built from old files (bug 6)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Between your code and the platform:&lt;/strong&gt; retried saves (bug 2), restricted picklists (bug 3) and client-side caching (bug 5)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Between your org and the buyer's:&lt;/strong&gt; code that changes their data the moment it's deployed (bug 4)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;At the edges:&lt;/strong&gt; inputs nobody types on purpose (bug 7)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Passing tests prove the code does what you thought of. A tester clicking through, and a reviewer who has never seen the code, find what you didn't. Do both before you call something production-ready.&lt;/p&gt;




&lt;p&gt;All seven fixes are in v1.1 of the &lt;strong&gt;ApexCraft Apex + LWC Starter Kit&lt;/strong&gt;: a trigger framework, service and selector layers, a rollback-proof logger, async job templates and six LWC components, with 68 Apex and 45 Jest tests. &lt;a href="https://apexcraftstudio.gumroad.com/l/starter-kit" rel="noopener noreferrer"&gt;See it on Gumroad&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Have you hit any of these in your own org? Tell me in the comments.&lt;/p&gt;

</description>
      <category>salesforce</category>
      <category>apex</category>
      <category>lwc</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
