Intermediate 25 min read

Code Review Best Practices

By the end of this lesson, you'll be able to:

  • Explain the purpose of code review beyond just "catching bugs"
  • Identify what a reviewer should check in a real Apex change
  • Recognize the difference between a blocking comment and a suggestion

Prerequisites: "SOLID Principles in Apex"

What code review is actually for

Catching bugs before they ship is one benefit of code review, but not the only one — it's also how a team spreads knowledge (a reviewer learns what changed and why), keeps a shared codebase consistent (naming, patterns, structure), and gives newer developers concrete, specific feedback on real code they wrote.

What to actually check

A useful review checklist for an Apex change:

  • Correctness — does the logic actually do what the PR description claims?
  • Bulkification (Module 7) — is there a SOQL query or DML statement inside a loop?
  • Naming and clarity (this module's earlier lesson) — would a stranger understand this code?
  • Tests — are there tests, and do they cover the real edge cases, not just the happy path?
  • Scope — does this PR do exactly one thing, or has unrelated code snuck in?

Blocking comments vs suggestions

BLOCKING: "This SOQL query is inside a for loop — this will hit
           governor limits with more than 100 records. Please move
           it outside the loop before this can merge."

SUGGESTION: "Optional: `isEligible` might read slightly clearer as
             `hasQualifyingScore` — up to you."

Not every comment carries the same weight. A blocking comment identifies something that must be fixed before merging (a real bug, a governor limit risk); a suggestion offers an optional improvement the author can take or leave. Being explicit about which is which respects the author's time and avoids unnecessary back-and-forth.

Exercise

As a comment, write one blocking review comment for this code (hint: think about governor limits from Module 7).

Show hint

A DML statement runs inside a for loop.

APEX

Code Review Best Practices Quiz

1. Besides catching bugs, what is another key purpose of code review?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

Code review catches bugs, but its bigger value is spreading knowledge across a team and keeping a shared codebase consistent — reviewing well is its own skill.