---
title: "Run Apex code in command line"
url: "https://blog.beyondthecloud.dev/tips/run-apex-code-in-command-line"
category: "DevOps & CLI"
tags: "apex, sfdx"
published: "2026-07-26"
---

# Run Apex code in command line

Did you know that you don’t have to open developer console to run apex scripts via Anonymous Apex? You don’t even have to open any IDE or create a text file, simply put your code in…

### Run Apex Anonymous code in command line

Did you know that you don’t have to open developer console to run apex scripts via Anonymous Apex? You don’t even have to open any IDE or create a text file, simply put your code in command line interface.

All you have to do is to use the sf command:

```bash
sf apex run
```

This will start interactive shell. You can use enter to go to next line, when you are done with writing your code, use Ctrl+D to execute code
