ApexDoc and Documentation Standards
By the end of this lesson, you'll be able to:
- Write a comment block documenting a class or method's purpose
- Explain what makes a comment worth writing versus noise
- Recognize ApexDoc as a convention, not a compiler requirement
Prerequisites: "Namespaces"
The ApexDoc comment shape
/**
* Calculates the commission owed on a real estate sale.
*
* @param salePrice the final agreed sale price
* @param commissionRate the agreed commission percentage (e.g. 5 for 5%)
* @return the commission amount
*/
public Decimal calculateCommission(Decimal salePrice, Decimal commissionRate) {
return salePrice * (commissionRate / 100);
}
/**—/**(the extra*compared to a regular/* */comment) opens the ApexDoc convention.* Calculates the commission owed on a real estate sale.— a one-line summary of the method's purpose.*— a blank comment line for spacing.* @param salePrice the final agreed sale price— documents the first parameter.* @param commissionRate the agreed commission percentage (e.g. 5 for 5%)— documents the second parameter.* @return the commission amount— documents the return value.*/— closes the comment block.public Decimal calculateCommission(Decimal salePrice, Decimal commissionRate) {— the method the comment describes.return salePrice * (commissionRate / 100);— its logic.}— closes the method.
This structured shape is readable by both humans and documentation-generating tools.
What makes a comment worth writing
// BAD: restates what the code already says
i++; // increment i by 1
// GOOD: explains something the code alone can't
// Salesforce processes discounts before tax, so this must run
// before the VAT calculation below, not after.
applyDiscount(order);
// BAD: restates what the code already says— a label for the anti-pattern below.i++; // increment i by 1— a comment that just repeats what the line obviously does — noise, not value.- (blank line)
// GOOD: explains something the code alone can't— a label for the good pattern below.// Salesforce processes discounts before tax, so this must run— explains the why: a non-obvious business rule.// before the VAT calculation below, not after.— continues the explanation.applyDiscount(order);— the line the comment is justifying — something a reader genuinely couldn't infer from the code alone.
A convention, not a requirement
Apex compiles identically whether or not a method has an ApexDoc block above it — this is a team and community convention, not a language rule. Well-documented public methods (the ones other developers will actually call) tend to matter most; small private helper methods with a clear name often need no comment at all.
Exercise
Write an ApexDoc comment block above this method describing its purpose, one @param for each parameter, and an @return line.
Show hint
Follow the /** ... @param ... @return */ shape shown above.
ApexDoc and Documentation Standards Quiz
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
ApexDoc is a comment convention for documenting what a class or method does and why — not enforced by the compiler, but valuable for anyone (including future you) reading the code later.