The Apex mistakes I still see in every org

Fifteen years of the same five mistakes: queries in loops, tests without assertions, triggers with opinions, hardcoded Ids, and empty catch blocks.

The Apex mistakes I still see in every org

Fifteen years of the same five mistakes: queries in loops, tests without assertions, triggers with opinions, hardcoded Ids, and empty catch blocks.

Queries in loops, still

The 101st SOQL query has been throwing the same exception since 2008 and it remains the number one production incident I get called about. The fix is a pattern, not a talent — collect, query once, map, loop.

Tests that assert nothing

Coverage without assertions is a donation to the deployment gods. If the method's behaviour changed completely and the test still passed, it was never a test.

The empty catch block

catch (Exception e) {} is a decision to find out about failures from your users. Log it, rethrow it, or write the comment explaining why silence is genuinely correct — there is no fourth option.

Keep reading

More from the blog