Improved Apex Language Support for ".apex" execute anonymous files
See original GitHub issueSummary
When writing Apex in a .apex
file to be used for anonymous execution, the Apex language server marks the first line of code as invalid with an “Unexpected token” error. It seems the language server expects a class or trigger keyword and does not know what to do with simple lines of Apex outside that context.
Steps To Reproduce:
- Create an
.apex
extension file inside a dx project - Write a single line of apex like so:
System.debug('Hello World');
Expected result
No error message appears in the “Problems” output panel.
Actual result
The following error message appears in the “Problems” output panel:
Unexpected Token: 'System.debug'. (1,1)
.
Additional information
VS Code Version: 1.23.1
SFDX CLI Version: 6.17.0-b1f53723b9
OS and version: macOS High Sierra 10.13.4
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Improved Apex Language Support for ".apex" execute ...
apex file to be used for anonymous execution, the Apex language server marks the first line of code as invalid with an "Unexpected...
Read more >Executing Anonymous Apex Code - Salesforce Help
The Execute Anonymous Apex tool in the Developer Console runs the Apex code you enter using ExecuteAnonymous and generates a debug log with...
Read more >Apex: Basics and Anonymous Execution - YouTube
In this Quick Take, we'll get you started with Apex and see how and where to write Apex code. You'll learn how to...
Read more >Create a class using execute anonymous
If you create a apex file and drop your code in there, it'll give you error messages to show you where you are...
Read more >Apex Developer Guide - Salesforce Implementation guides
Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ntotten - Yes, we need to make changes to the Apex LS to make it understand execute anonymous – I don’t think it’s big but it needs to be done.
As you can see in the screenshot above in the issue, the LS is saying there is an error in that file. That’s because it’s treating .apex as a .cls file and the only top-level constructs allowed in a .cls file are
class|enum|interface
declaration. You cannot have standalone statements like you can with execute anonymous.I’m not opposed to doing this. I just want to know if .apex is the extension convention that we want to adhere to. It’s not documented anywhere in our docs.
Belatedly closing this. The original issue has been resolved.