Intermediate 25 min read

Annotations Overview

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

  • Explain what an annotation is: metadata attached to a class or method
  • Recognize @isTest and @AuraEnabled as two annotations you'll meet soon
  • Distinguish an annotation from a regular keyword

Prerequisites: "Keywords Tour"

What an annotation looks like

@isTest
private class CalculatorTest {
    @isTest
    static void testAddition() {
        System.assertEquals(4, 2 + 2);
    }
}

@isTest above the class tells Salesforce "this entire class exists only to run tests — don't count it toward certain limits, and don't deploy it as regular application logic." The annotation itself runs no code; it's an instruction about the code beneath it.

Annotation vs keyword

A keyword like public or static is part of the core language grammar — every Apex compiler must understand it to compile the class at all. An annotation like @isTest is metadata layered on top — it changes how Salesforce's platform treats the code (testing rules, API exposure, scheduling), not the fundamental meaning of the Apex statements themselves.

A few you'll meet in later modules

  • @isTest — marks a class or method as test-only code (a later Testing module goes deep on this).
  • @AuraEnabled — exposes a method so a Lightning Web Component can call it (covered in the LWC module).
  • @future — marks a method to run asynchronously, later, outside the current transaction (covered in the Asynchronous Apex module).

You don't need to use any of these yet — recognizing the shape (@SomeName above a class or method) is the goal of this lesson.

Exercise

As a comment, explain in your own words what makes an annotation different from a keyword like public.

Show hint

Think about what each one actually controls.

APEX

Annotations Overview Quiz

1. What does an annotation like @isTest do?

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

An annotation is a piece of metadata attached above a class or method using @ — it doesn't change what the code does directly, but tells Salesforce (or a tool) something important about how to treat it.