Skip to content

Annotations

Marks a zero-parameter function as a test case. The vertex test command discovers and runs all @Test functions in *_test.vtx files.

@Test
fn add_two_numbers(): Void {
assert 1 + 1 == 2
}

Rules enforced by the checker:

  • The function must have no parameters (error E136).
  • @Test may only appear in files whose name ends in _test.vtx (error E137).
  • Non-test modules may not import test modules (error E138).

@Test functions are exempt from the unused-private-function warning (W005) because the test runner calls them externally.

See the Testing reference for the full testing guide.

Three annotations control the Apex sharing modifier on the generated outer class. They are placed at the very top of a .vtx file, before any import or declaration:

@WithoutSharing
import lang.db
pub fn run(): Void {
db.insertAccount(...)
}
AnnotationGenerated Apex class header
(none)public with sharing class Module_Name { ... }
@WithSharingpublic with sharing class Module_Name { ... }
@WithoutSharingpublic without sharing class Module_Name { ... }
@InheritedSharingpublic inherited sharing class Module_Name { ... }

Default is with sharing. This is the safe default per Apex security best practices and aligns with PMD’s ApexSharingViolations rule.

Rules:

  • At most one sharing annotation per module. A second one is an error (E141).
  • Sharing annotations take no arguments. Arguments are an error (E142).
  • Unknown module-level annotation names are an error (E140).
  • Sharing annotations are a no-op in JIT mode and in anonymous-Apex paths.
  • Inner classes inherit sharing from the outer class.

Marks a function as callable from Lightning components. The function must return Result<T, AuraError>. The codegen unwraps the Result at the Apex boundary: Ok(value) returns value directly; Error(AuraError(msg)) throws new AuraHandledException(msg).

@AuraEnabled
fn getContacts(
): Result<List<Contact>, AuraError> { ... }
@AuraEnabled(cacheable: true)
fn getAccountName(
id: String,
): Result<String, AuraError> { ... }

Marks a single-variant record type as an LWC data contract. The codegen emits @AuraEnabled on every field and drops final from fields (required for LWC serialization/deserialization).

The type must be a single-variant record (variant name matches the type name). Applying @AuraEnabled with arguments or to a multi-variant type is an error.

@AuraEnabled
pub type BookDto {
BookDto(name: String, authorName: String, price: Decimal)
}
@AuraEnabled
pub fn getBook(id: String): Result<BookDto, AuraError> { ... }

Generates:

public class BookDto {
@AuraEnabled
public String name;
@AuraEnabled
public String authorName;
@AuraEnabled
public Decimal price;
public BookDto(String name, String authorName, Decimal price) {
this.name = name;
this.authorName = authorName;
this.price = price;
}
}