Modules and Imports
File = module
Section titled “File = module”In Vertex, every .vtx file is a module. No explicit module declaration is needed. The module name is derived from the filename:
accounts.vtx→ moduleaccountsbilling/invoices.vtx→ modulebilling.invoices
Visibility
Section titled “Visibility”Declarations are private by default. Use pub to export:
pub fn findById(id: String): Option<Account> { ... } // exportedfn validate(a: Account): Bool { ... } // privateImport forms
Section titled “Import forms”Bare import. Access symbols via a qualifier:
import accounts
let acc = accounts.findById("001")For nested modules, the qualifier is the last path segment:
import billing.invoices
let inv = invoices.create()Aliased import. Choose your own qualifier:
import billing.invoices as inv
let i = inv.create()Selective import. Bring specific symbols directly into scope:
import accounts.{ findById, Account }
let acc = findById("001") // no qualifier neededApex class names
Section titled “Apex class names”Each module maps to an Apex class when compiled:
| Module path | Apex class |
|---|---|
accounts | Accounts |
billing/invoices | Billing_Invoices |
lang/greeter | Lang_Greeter |
Error codes
Section titled “Error codes”| Code | Meaning |
|---|---|
E122 | Module not found |
E123 | Symbol not found in module’s public API |
E124 | Attempted access to a private declaration |
E125 | Cyclic import detected |
E126 | Name conflict from two selective imports |
Running scripts with imports
Section titled “Running scripts with imports”vertex run supports imports without a build step. Point it at any entry script
and it discovers the project automatically by walking upward from the file’s
directory to find sfdx-project.json:
vertex run scripts/hello.vtxOnly the transitively reachable modules are loaded. Files in src/ that are
not imported are never touched.
A file with no imports runs anywhere. No project required.
See the Imports reference for the
full discovery rules and --sf preconditions.
Next steps
Section titled “Next steps”- Imports reference: full spec including opaque type error codes
- Constants reference,
pub constfor exported values - Annotations: controlling Apex sharing modifiers per module