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.
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.
1. Page 4 showed page 1
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.
The server pages with a keyset cursor: "give me rows after the last one you saw", which avoids SOQL's 2,000-row OFFSET limit. The browser was still running the previous 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.
The tests passed because they called each version with the arguments it expected. Nothing tested an old client against the new server.
Fix: 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:
Boolean keyset = KEYSET_FIELDS.containsKey(field)
&& (page == 1 || cursorId != null);
Check your code: when you change an @AuraEnabled method's contract, ask what an old client would get. Then hard-refresh (Ctrl+Shift+R) before you trust a manual test.
2. The recursion guard skipped retried records
Most tutorials stop trigger recursion with a static "already ran" flag. That silently skips records 201 and up, because Salesforce runs triggers in chunks of 200. My guard tracked record Ids instead, and a 201-record test proved it worked.
But a set of Ids has its own trap. When a save runs with all-or-none off (Database.update(records, false), Data Loader, the API) and some records fail, Salesforce rolls back and re-runs the trigger for the records that succeeded. Static variables are not 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.
Fix: for logic that is safe to repeat, like a roll-up, skip the guard. Compare old and new values, and recalculate:
Boolean changed = project.Budget__c != old.Budget__c
|| project.Status__c != old.Status__c
|| project.Account__c != old.Account__c;
Keep an Id guard only for work that must happen exactly once, like sending a notification.
3. Detailed logs vanished without an error
The logger publishes a platform event, and a subscriber trigger saves it as a Log__c record. Because the event publishes immediately, the log survives even when the transaction rolls back.
The event's Level__c field took any LoggingLevel name. The Log__c 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.
The tests never logged below DEBUG, so they never noticed.
Fix: store anything finer than DEBUG as DEBUG:
private static String storedLevel(LoggingLevel level) {
return SEVERITY.get(level) < SEVERITY.get(LoggingLevel.DEBUG)
? 'DEBUG' : level.name();
}
Check your code: for every restricted picklist, find each place that writes to it, and test with a value outside the list.
4. The example trigger changed real data
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.
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.
Fix: example code ships switched off. The framework reads an on/off switch from custom metadata, so the record now sets Is_Active__c to false, and the tests turn the handler on only while they run:
TriggerHandler.settingOverrides.put('AccountTriggerHandler', true);
Check your code: if you ship anything to another org, list what changes the moment it's deployed. That list should be empty.
5. refresh() could show stale data
The data table has a public refresh() method, so a parent component can reload it after saving a record. The Apex method behind it was @AuraEnabled(cacheable=true).
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.
Jest mocks the Apex call, so no unit test can catch this. It only shows up in a real browser.
Fix: remove cacheable=true from methods that must return current data, or use @wire with refreshApex(). Keep caching for searches and reference data, where an old answer does no harm.
6. The no-CLI install shipped old code
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.
Fix: 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.
7. A huge page number overflowed
Offset paging computed (page - 1) * size 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.
Fix: compare first, multiply after:
if (page - 1 > maxOffset / size) {
throw handled('Sorting by ' + field + ' pages through the first 2,000 rows.');
}
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.
What I'd tell myself before shipping
Every bug above lived in a gap the tests couldn't see:
- Between versions: an old client calling a new server (bug 1), and a release zip built from old files (bug 6)
- Between your code and the platform: retried saves (bug 2), restricted picklists (bug 3) and client-side caching (bug 5)
- Between your org and the buyer's: code that changes their data the moment it's deployed (bug 4)
- At the edges: inputs nobody types on purpose (bug 7)
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.
All seven fixes are in v1.1 of the ApexCraft Apex + LWC Starter Kit: 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. See it on Gumroad.
Have you hit any of these in your own org? Tell me in the comments.
Top comments (0)