Annotations
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.
To add an annotation to a method, specify it immediately before the method or class definition. For example:
Apex supports these annotations.
-
Apex REST annotations:
@ReadOnly@RestResource(urlMapping='/yourUrl'), where yourURL is a placeholder value@HttpDelete@HttpGet@HttpPatch@HttpPost@HttpPut
You can use multiple annotations for the same class or method. Specify each annotation on a separate line immediately before the class or method definition. Some annotations can’t be used together. If applicable, these limitations are documented on the page for the annotation.
-
BeforeClass Annotation (Developer Preview)
Use the
BeforeClassannotation to set up test data shared across methods within an integration test class. -
Use the
Futureannotation to identify methods that run asynchronously. A future method runs when Salesforce has available resources. -
IntegrationTest Annotation (Developer Preview)
Use the
IntegrationTestannotation to mark both classes and methods that are used in integration testing. -
Use the
InvocableMethodannotation to identify methods that can be run as invocable actions. -
To identify variables used by invocable methods in custom classes, use the
InvocableVariableannotation. -
Use the
@IsTestannotation to define classes and methods that only contain code used for testing your app. -
The
@JsonAccessannotation defined at Apex class level controls whether instances of the class can be serialized or deserialized. If the annotation restricts the JSON or XML serialization and deserialization, a runtimeJSONExceptionexception is thrown. -
This annotation does nothing in Apex but can be used to provide information to third-party tools.
-
Methods defined with the
@TestSetupannotation are used for creating common test records that are available for all test methods in the class. -
TearDown Annotation (Developer Preview)
Use the
TearDownannotation to mark a cleanup method that runs after the test completes, regardless of pass or fail.