Anonymous Apex

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.

In The Welkin Suite, Anonymous Apex is treated similarly to the usual Apex code with all the supported features for Apex Code Assistance.

Executing Anonymous Apex

To execute Anonymous Apex do the following:

  1. open any .anonymous file or create a new one via the Add new item option in the Solution Explorer,
  2. write the code that you want to test,
  3. click on the Execute Anonymous Apex button.

Executing Anonymous Apex

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.

Execute your Anonymous Apex files without opening them

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.

Execute selected code as Anonymous Apex

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.

Execute highlighted

Additionally, you can execute Anonymous Apex code using a context menu or hotkeys within the Anonymous Apex editor:

  • Execute Anonymous Apex - Alt+E
  • Execute highlighted - Alt+R

Hotkeys for Anonymous Apex execution

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.

Organizing the Anonymous Apex

In this section:

This also may be helpful:

Last modified: 2018/08/21 15:18

footer image