Basics

Apex Comments

Apex Comment Syntax

Apex comments use // and /* */ with ApexDoc for APIs.

Introduction to Apex Comments

Comments are essential in programming to explain code logic, make it readable, and maintainable. In Apex, comments can be single-line or multi-line, and there's also a way to generate documentation using ApexDoc.

Single-Line Comments

Single-line comments in Apex start with //. Everything after these characters on the same line is considered a comment.

Multi-Line Comments

Multi-line comments begin with /* and end with */. This is useful for commenting out larger blocks of code or adding detailed explanations.

ApexDoc for API Documentation

ApexDoc is a tool used to generate documentation for your Apex classes. Similar to Javadoc, ApexDoc comments begin with /** and are placed before classes, methods, or properties.

Best Practices for Using Comments in Apex

Effective commenting can greatly enhance code readability and maintainability. Follow these best practices:

  • Use comments to explain why code exists, not what it does.
  • Avoid redundant comments that state the obvious.
  • Keep comments up-to-date with code changes.
  • Use ApexDoc for public APIs to ensure comprehensive documentation.
Previous
Loops