The Developer Console lets you execute Apex code statements. It also lets you execute Apex methods within an Apex class or object. In this tutorial you open the Developer Console, execute some basic Apex statements, and toggle a few log settings.
Activating the Developer Console:
To execute Apex code and view the results of the execution, use the Developer Console. The detailed execution results include not only the output generated by the code, but also events that occur along the execution path. Such events include the results of calling another piece of code and interactions with the database.
Activating the Developer Console:
After logging into your Salesforce environment, the screen displays the current application you’re using (in the diagram below, it’s Warehouse), as well as your name.
- Click your name, and then Developer Console.
The Developer Console opens in a separate window.
- If this is your first time opening the Developer Console, you can take a tour of the Developer Console features. Click Start Tour and learn more about the Developer Console.
You can open the Developer Console at any time, and activate it again by following this lesson.
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 a System Log view. The System Log view is the Developer Console tool you’ll use most often.
- Click in the Execute field at the top of the Developer Console.
- In the Enter Apex Code window, enter the following text: System.debug( 'Hello World' );
- Deselect Open Log and 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 a System Log view. You can open multiple logs at a time to compare results.
Double-click a log to open it in a System Log view. You can open multiple logs at a time to compare results.
The System Log view is a context-sensitive execution viewer that shows the source of an operation, what triggered that operation, and what occurred afterward. You can use this view to inspect debug logs that include database events, Apex processing, workflow, and validation logic.
Within a System Log view, you’ll use the Execution Log panel a lot. It displays the stream of events that occur when code executes. Even a single statement generates a lot of events. The System Log 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.
- Click in the Execute field and enter the following code:
System.debug( 'Hello World' ); System.debug( System.now() ); System.debug( System.now() + 10 );
- Check Open Log and click Execute.
- In the Execution Log panel, click the Executable checkbox. This limits the display to only those items that represent executed statements. For example, it filters out the cumulative limits.
- To filter the list to show only USER_DEBUG events, enter: USER in the Filter field.
Congratulations—you have successfully executed code on the Force.com platform and viewed the results! You’ll learn more about the Developer Console tools in later tutorials.
To execute Apex code and view the results of the execution, use the Developer Console. The detailed execution results include not only the output generated by the code, but also events that occur along the execution path. Such events include the results of calling another piece of code and interactions with the database.
No comments:
Post a Comment