Your first Salesforce project
This page walks you from a single-file Vertex script to a real project that builds to Apex class files and deploys to a Salesforce org.
It assumes you have:
- Vertex installed.
- The Salesforce CLI (
sf) installed and authenticated to a scratch org or sandbox.
Project layout
Section titled “Project layout”A Vertex project is any directory containing an sfdx-project.json
file. The file tells the Salesforce tooling where your Apex source
lives; Vertex uses the same file to locate your Vertex source.
The conventional layout:
my-project/├── sfdx-project.json├── src/ # .vtx source goes here│ └── hello.vtx└── force-app/ └── main/ └── default/ └── classes/ # vertex build writes .cls files hereA minimal sfdx-project.json:
{ "packageDirectories": [ { "path": "force-app", "default": true } ], "sourceApiVersion": "66.0"}Write an entry point
Section titled “Write an entry point”Vertex programs that run as real Apex classes expose a pub fn run
entry point. Create src/hello.vtx:
pub fn run(): Void { debug "Hello from Vertex on Salesforce!"}This compiles to a public static void vtx_run() method on a generated
Apex class.
From the project root:
$ vertex buildSuccess! Built 1 class(es) to force-app/main/default/classes/Look inside force-app/main/default/classes/ and you will see a
.cls file and a .cls-meta.xml file ready for deployment.
Deploy
Section titled “Deploy”$ sf project deploy start --target-org <alias>Use the alias you set up with sf org login. Do not pass --source-dir
or --metadata: the sf CLI tracks local changes internally.
Run it
Section titled “Run it”Create run-hello.apex:
Hello.vtx_run();Then:
$ sf apex run --target-org <alias> --file run-hello.apexYou should see your debug line in the Apex log.
The full development loop
Section titled “The full development loop”For day-to-day iteration, you rarely need the org. The loop is:
- Edit a
.vtxfile. vertex run <file>to execute it locally (millisecond feedback).vertex testto run your*_test.vtxfiles.vertex buildandsf project deploy startwhen you are ready to ship.
See The vertex CLI for the full command reference and Testing for the test runner.
- Editor setup: get syntax highlighting, diagnostics, and completions in your editor.
- Guides: Building for Salesforce: a
deeper look at SObjects, DML, and
@AuraEnabled.