ApexSensei

Drills › Write Apex

Comments that survive review

Write Apex · Beginner · 5 min · Runs in the browser, no org needed · Free

Scenario. A teammate left scratch logs in an Account setup script. Make the intent clear before review.

Explain why an Account field is set, switch off scratch logs, and keep the useful log running.

What you will learn

Comments explain code without changing what it does. Use // for one line and /* ... */ for a block. Put a comment on its own line, above the code it explains, and say why, not what.

// Matches the integration's retry policy
Integer retryLimit = 3;

A short comment at the end of the line also works, but the line above is house style.

Gotcha. Code inside a comment does not run. A commented-out System.debug prints nothing.

The task

Tidy this Account script so reviewers see why Industry is set and only the useful log still runs.

You don't need to understand every line yet. This drill is only about comments.

Examples:

  • // Finance clients get the capital checklist on its own line above acc.Industry = 'Finance'; → the assignment still runs
  • /* before the two scratch logs and */ after them → those two logs print nothing

Requirements:

  1. Add a // comment on its own line above the Industry line. Say why the value is Finance.
  2. Wrap both scratch System.debug lines in one /* ... */ block.
  3. Keep the Account: debug line outside the block so it still runs.
  4. Leave the other Account lines as they are.

Starter code

Account acc = new Account();
acc.Name = 'RidgePoint Capital';
acc.Industry = 'Finance';
System.debug('scratch');
System.debug('delete me');
System.debug('Account: ' + acc.Name);

When it passes

A `//` comment explains the Industry value, both scratch logs sit inside one `/* ... */` block, and only the `Account:` log still runs.

Try this drill free

You write the Apex yourself. ApexSensei runs it and tells you what passed and what did not.

Hello, ApexSensei ›