13

Is it possible / How would I run a block of Apex anonymous code from Visual Studio Code?

13

In the command palette, if you type "sfdx ex" you will be offered this if you have some Apex text selected:

SFDX: Execute Anonymous Apex with Currently Selected Text

or this:

SFDX: Execute Anonymous Apex with Editor Contents

if you don't.

Not too sure why there is also this .apex file thing too. As the project is open source you can see open issues, all issues, pull requests etc here https://github.com/forcedotcom/salesforcedx-vscode/issues.

  • As far as I know, the .apex file extension is simply to add code highlighting (and perhaps other IDE language features? though no intellisense on my test) for saved scripts--rather than saving them in the project as a .txt file, for instance. – Brent Bow Aug 5 at 22:40
3

For all those command liners, you can also use force:apex:execute

sfdx force:apex:execute -u MyConnectedOrg

Start typing straight into the terminal or copy/paste your code of interest. Ctrl+D will execute the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.