Anonymous Apex is an excellent tool for testing new functionality or debugging your code without building this code to the org. The Anonymous Apex helps you to get detailed logs and to check new development approaches.
Executing Anonymous Apex
To execute Anonymous Apex do the following:
- write the code that you want to test,
- click on the Execute Anonymous Apex button.
If you already have a saved Anonymous Apex file, you can execute it without opening. In the Solution Explorer, right-click on a necessary Anonymous Apex file and select the Execute Anonymous Apex option from its context menu.
The file won't be opened itself, but its execution log file will be shown after the execution is finished. The log file opening, in this case, isn't related to the 'Open execution logs' setting which is present in the Anonymous Apex file when it is opened.
If you'd need to execute some certain part of your code separately, you can do this in just 3 clicks and about 5 seconds. Simply select the code in the editor, right-click on it, and select the Execute selected code as Anonymous Apex option. The IDE will execute that block of code and will show you a log file.
In cases, when you have lots of different functionality snippets in one anonymous file, or just want to test only a part of the code, use the Execute highlighted option. Select the necessary code lines and click on the Execute highlighted button.
You can explore the log related to this code execution right after it is finished. To do so, check the box Open execution logs at the top right corner of the editor. As soon as the code is executed, you will get the log file opened in the Debug Logs Viewer. The option
Open execution logs remembers its last state in the current session, so the setting is kept the same that you've selected previously. When you start the new session in The Welkin Suite, the setting for this option returns to the default state — the filter is unselected.
Errors in Anonymous Apex
The Welkin Suite handles all the errors when running Anonymous Apex. Execution errors are displayed in the Error List Panel, so you can check the reason for a fail and quickly revise your code.
Organizing the Anonymous Apex
You can easily store the parts of the code for different purposes (for example, debugging, interacting with outer services, etc.) in the separate files. In The Welkin Suite, you are able to create an unlimited amount of
.anonymous files and organize them as you want: create appropriate folders and logically group them.
In this section:
This also may be helpful: