---
schema_version: "1"
id: 39573e22c7917080609a4b0d8f3d0e59b015036d8f2af88ce3f734302b1de3f5
title: Document Apex Constructs and Features
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_doc_constructs.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_doc_constructs.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 85cdf5462a82d86d24df0f1e9e41b3c17efb49fe62b7247a3f57b3a5b091d25b
description: Apex has unique constructs and platform-specific features that require particular attention in documentation. Use these guidelines to document these elements with ApexDoc.
---
# Document Apex Constructs and Features

Apex has unique constructs and platform-specific features that require particular attention in documentation. Use these guidelines to document these elements with ApexDoc.

## Classes

When you document an [Apex class](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_understanding.htm "As in Java, you can create classes in Apex. A class is a template or blueprint from which objects are created. An object is an instance of a class."), provide a comprehensive overview of the class’s purpose, responsibilities, and key characteristics.

In the summary sentence, describe the class’s ‌overall purpose. After the summary sentence, explain the rationale for the class’s [sharing model](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm "Use the with sharing or without sharing keywords on a class to specify whether sharing rules are enforced. Use the inherited sharing keyword on a class to run the class in the sharing mode of the calling class. The default sharing mode is with sharing.") if it’s not obvious. For example, explain why the class uses without sharing for a specific privileged operation. We also recommend using tags such as @author, @version, @since, @see, and @group, which all provide valuable metadata.

Here’s an example ApexDoc comment for the DataAggregationService class.

/\*\*
 \* This service class handles critical data aggregation tasks.
 \* It operates using 'without sharing' to ensure access to all necessary
 \* records for calculation, irrespective of the running user's sharing rules.
 \* Care must be taken when calling methods from this class.
 \* @author Jane Doe
 \* @since 0.1.0
 \*/
public without sharing class DataAggregationService {
    //...
}

## Interfaces

[Apex interfaces](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_interfaces.htm "An interface is like a class in which none of the methods have been implemented—the method signatures are there, but the body of each method is empty. To use an interface, another class must implement it by providing a body for all of the methods contained in the interface.") define a contract for what other classes can do without specifying how they do it. Focus your ApexDoc comments on this contract. In the main description, document the interface’s overall purpose and the contract that it defines. Standard metadata tags such as @author, @version, @since, and @see are also applicable.

Document each method declaration in the interface as a standard method. Clearly explain the method’s expected behavior, parameters, and return values. This documentation sets expectations for any class that implements the interface.

For an example of an interface with an ApexDoc comment, see [ApexDoc Examples](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_doc_examples.htm "See practical examples of ApexDoc comments applied to various Apex constructs.").

## Enums

[Enums](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_enums.htm "An enum is an abstract data type with values that each take on exactly one of a finite set of identifiers that you specify. Enums are typically used to define a set of possible values that don’t otherwise have a numerical order. Typical examples include the suit of a card, or a particular season of the year.") in Apex define an abstract data type with a finite set of named constant values. In the main description, document the enum’s purpose and the set of concepts that it represents. You can also use standard tags such as @author, @version, @since, and @see.

Clarify individual enum constants if their names aren’t self-explanatory. Either describe a constant’s definition in the enum type’s ApexDoc main description, or use standard block comments that directly precede the line for the constant.

Apex enums implicitly include methods such as values(), valueOf(String), name(), and ordinal(). These standard methods generally don’t require explicit documentation within each specific enum’s ApexDoc comment.

Here’s an example ApexDoc comment for the Season enum.

/\*\*
 \* Potential seasons of the year
 \*/
public enum Season {
  WINTER,
  SPRING,
  SUMMER,
  FALL
}

## Methods and Constructors

[Method](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining_methods.htm "Learn how to define Apex methods. Understand the differences between passing method arguments by value and passing method arguments by reference.") and [constructor](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_constructors.htm) documentation is critical for understanding how to use an Apex class.

When you document method and constructor parameters, use the @param block tag. Each parameter must have a corresponding @param tag. In the parameter description, describe the parameter’s name, its purpose, and any expectations regarding its type or content. Descriptions can include statements such as ‌“Cannot be null” or “A valid 18-character ID”.

For methods that return values, use the @return block tag. In the description, specify what is returned, including conditions for null values or specific data structures. Descriptions can include statements such as “A List of Account sObjects matching the filter criteria; an empty list if no matches are found.”

Use the @throws block tag to list all significant checked and unchecked exceptions that the method can explicitly throw, along with the conditions causing them. This documentation is crucial for identifying gaps in error handling.

For examples of methods and constructors with ApexDoc comments, see [ApexDoc Examples](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_doc_examples.htm "See practical examples of ApexDoc comments applied to various Apex constructs.").

## Properties and Variables

Document public or global properties and class member variables that form part of a class’s public API.

In the ApexDoc comment’s main description section, explain the property’s purpose, its data type if it’s unclear from the method declaration, and any important usage notes. For example, include whether the property is read-only after initialization, or its default value. Block tags such as @see, @since, and @deprecated can also be applicable.

Here’s an example ApexDoc comment for the public maxRetries variable.

/\*\*
 \* Stores the maximum number of retry attempts for an operation.
 \* Defaults to 3 if not explicitly set.
 \* @since 0.1.1
 \*/
public Integer maxRetries {
  get {
    return maxRetries ?? 3;
  }
  set { maxRetries = value; }
}

## Triggers

[Apex triggers](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm "Apex can be invoked by using triggers. Apex triggers enable you to perform custom actions before or after changes to Salesforce records, such as insertions, updates, or deletions.") are event-driven pieces of code that execute in response to specific database operations. Apex trigger definitions provide significant context, so we strongly recommend that you delegate all business logic to a separate handler class or a trigger framework. Therefore, ApexDoc doesn’t have any trigger-specific comment specifications.

However, you can still include standard ApexDoc tags such as @since and @see. For example, here’s a ApexDoc comment for the Opportunity trigger.

/\*\*
 \* @since 1.3.2
 \*/
trigger OpportunityTrigger on Opportunity (
  before insert,
  after insert,
  before update,
  after update,
  before delete,
  after delete,
  after undelete
) {
  new OpportunityTriggerHandler().run();
}

## Annotations

[Apex annotations](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation.htm "An Apex annotation modifies the way that a method or class is used, similar to annotations in Java. Annotations are defined with an initial @ symbol, followed by the appropriate keyword."), such as @AuraEnabled and @Future, modify the way a class or method is used by the platform and other code. For an element that has an annotation, document the implications of that annotation for the element’s behavior or usage.

Refer to this table as you write ApexDoc comments for elements with Apex annotations.

<table class="featureTable sort_table" summary="">
          <caption><span class="tablecap">Table 1. Document Common Apex Annotations</span></caption>


          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader  " id="d90055e311">Apex Annotation</th>

              <th class="featureTableHeader  " id="d90055e314">Guidance for the ApexDoc Comment of the Annotated Element</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_AuraEnabled.htm"><samp class="codeph nolang">@AuraEnabled</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">If the element is exposed to Lightning components for client-side access, document
                whether <samp class="codeph apex_code">(cacheable=<span class="keyword">true</span>)</samp>. Describe the implications
                of this cache setting.</td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm" title="Use the InvocableMethod annotation to identify methods that can be run as invocable actions."><samp class="codeph nolang">@InvocableMethod</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">If the element is callable from Flow Builder, explain the element’s function as an
                invocable action. Mention <samp class="codeph apex_code">label</samp> and <samp class="codeph apex_code">description</samp> attributes from the annotation if they provide
                important context. Use <samp class="codeph nolang">@param</samp> and <samp class="codeph nolang">@return</samp> for the element’s specific input and output
                structure.</td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableVariable.htm" title="To identify variables used by invocable methods in custom classes, use the InvocableVariable annotation."><samp class="codeph nolang">@InvocableVariable</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">Clarify the variable’s specific role, data type, and any constraints or expectations
                for the action.</td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_rest_resource.htm"><samp class="codeph nolang">@RestResource(urlMapping=...)</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">Describe the overall resource. Also document the annotated Apex REST methods (<samp class="codeph nolang">@HttpDelete</samp>, <samp class="codeph nolang">@HttpGet</samp>,
                <samp class="codeph nolang">@HttpPatch,</samp>
                <samp class="codeph nolang">@HttpPost</samp>, or <samp class="codeph nolang">@HttpPut</samp>) with their specific roles.
              </td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_deprecated.htm"><samp class="codeph nolang">@Deprecated</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">Include the <samp class="codeph nolang">@deprecated</samp> tag. Explain the reason
                for the deprecation and specify the recommended alternative.</td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_future.htm" title="Use the Future annotation to identify methods that run asynchronously. A future method runs when Salesforce has available resources."><samp class="codeph nolang">@Future</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">Describe the implications of running the method asynchronously. For example, you can
                specify whether the method runs in a separate transaction, describe governor limit
                considerations, and explain callout behavior.</td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_isTest.htm" title="Use the @IsTest annotation to define classes and methods that only contain code used for testing your app."><samp class="codeph nolang">@IsTest</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">
                <p class="p">Briefly describe the scenario or functionality being tested. Test documentation is often
                  excluded from public API docs. If <samp class="codeph nolang">seeAllData</samp> is
                  <samp class="codeph nolang">true</samp>, explain why this setting is necessary. If
                  <samp class="codeph nolang">onInstall</samp> is <samp class="codeph nolang">true</samp>, explain why this setting is necessary.
                </p>

              </td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_ReadOnly.htm"><samp class="codeph nolang">@ReadOnly</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">Explain if the element is used for performance with large query sets or specific
                APIs.</td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testsetup.htm" title="Methods defined with the @TestSetup annotation are used for creating common test records that are available for all test methods in the class."><samp class="codeph nolang">@TestSetup</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">Describe the common test data being created.</td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testvisible.htm"><samp class="codeph nolang">@TestVisible</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">Describe the rationale for the element’s annotation. For example, on private or
                protected member methods or variables, document “Visibility modified for testing
                purposes.”</td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_SuppressWarnings.htm" title="This annotation does nothing in Apex but can be used to provide information to third-party tools."><samp class="codeph nolang">@SuppressWarnings</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">Specify the warning that the third-party tool suppresses and briefly explain the
                rationale for the suppression if it’s not self-evident.</td>

            </tr>

            <tr>
              <td class="entry" headers="d90055e311" data-title="Apex Annotation"><a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_NamespaceAccessible.htm"><samp class="codeph nolang">@NamespaceAccessible</samp></a></td>

              <td class="entry" headers="d90055e314" data-title="Guidance for the ApexDoc Comment of the Annotated Element">Clarify if this annotation restricts exposure compared to global access or why this
                level of access is appropriate.</td>

            </tr>

          </tbody>

        </table>

#### See Also

- [ApexDoc Comment Structure and Tags](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_doc_format.htm "To promote consistency and parsability, ApexDoc comments have a defined structure and syntax. Each ApexDoc comment consists of a main description and a set of block and inline tags that provide information about the documented code element.")
- [ApexDoc Examples](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_doc_examples.htm "See practical examples of ApexDoc comments applied to various Apex constructs.")