05 Jun Using the Developer Console to Execute Apex Code
The Developer Console can look overwhelming, but it’s just a collection of tools that help you work with code. In this lesson, you’ll execute Apex code and view the results in the Log Inspector. The Log Inspector is a useful tool you’ll use often. 1. Click Debug > Open Execute Anonymous Window or CTRL+E. 2. In the Enter Apex Code window, enter the following text: System.debug( ‘Hello World’ ); Note: System.debug() is like using System.out.println() in Java (or printf() if you’ve been around a while ;-). But, when you’re coding in the cloud, where does the output go? Read on! 3. Deselect Open Log and then click Execute.
Every time you execute code, a log is created and listed in the Logs panel.
Double-click a log to open it in the Log Inspector. You can open multiple logs at a time to compare results. Log Inspector is a context-sensitive execution viewer that shows the source of an operation, what triggered the operation, and what occurred afterward. Use this tool to inspect debug logs that include database events, Apex processing, workflow, and validation logic. The Log Inspector includes predefined perspectives for specific uses. Click Debug > Switch Perspective to select a different view, or click CTRL+P to select individual panels. You’ll probably use the Execution Log panel the most. It displays the stream of events that occur when code executes. Even a single statement generates a lot of events. The Log Inspector captures many event types: method entry and exit, database and web service interactions, and resource limits. The event type USER_DEBUG indicates the execution of a System.debug() statement.
1. Click Debug > Open Execute Anonymous Window or CTRL+E and enter the following code:
System.debug( ‘Hello World’ );
System.debug( System.now() );
System.debug( System.now() + 10 );
2. Select Open Log and click Execute. 3. In the Execution Log panel, select Executable. This limits the display to only those items that represent executed statements. For example, it filters out the cumulative limits. 4. To filter the list to show only USER_DEBUG events, select Debug Only or enter USER in the Filter field.
“Explore – Techila Global Services, A Salesforce development company”