Your first Vertex program
This page assumes you have already installed Vertex
and vertex --version prints a version.
Hello, Vertex
Section titled “Hello, Vertex”Create a file called hello.vtx:
debug "hello, vertex!"Run it:
$ vertex run hello.vtxhello, vertex!That is it. No main function, no class wrapper, no sfdx-project.json,
no deploy. Vertex executes top-level statements in order, top to bottom.
debug is the output function
Section titled “debug is the output function”debug is the only way to produce observable output. It is an
expression: it evaluates its argument, prints it, and returns the
value so you can inspect mid-pipeline.
debug "hello"debug 42debug true
let sum = debug 1 + 2 // prints 3, then binds sum = 3Bindings
Section titled “Bindings”let name = "Alice"let age = 30
debug "Hello, ${name}! You are ${age}."All bindings are immutable by default. If you need to reassign:
mutable let counter = 0counter = counter + 1counter = counter + 1debug counter // 2The visible mutable keyword is deliberate. Reassignment is possible
but it stands out. See Bindings.
Doing something useful
Section titled “Doing something useful”Here is a complete program that pitches several of the ideas the tour will cover in more depth:
fn label(age: Int): String { if age < 18 { "minor" } else { "adult" }}
fn describe(name: String, age: Int): String { "${name} is ${label(age)} (age ${age})"}
debug describe("Alice", 30)debug describe("Bob", 15)Run it:
$ vertex run greet.vtxAlice is adult (age 30)Bob is minor (age 15)What just happened
Section titled “What just happened”- No deploy. Vertex ran your code locally via its built-in JIT.
- Compile-time guarantees. The types of
name,age, and the return oflabelwere all checked before anything ran. - Millisecond feedback. No org, no build step, no waiting.
- Your first Salesforce project: move from single files to a proper multi-file project that builds to Apex and deploys.
- Language Tour: a guided walk through every language feature.