Table of Contents

Salesforce developers often rely on Apex Code to build custom functionality tailored to their organization’s unique needs. However, understanding what happens behind the scenes when an Apex class is executed can be tricky. This is where the Salesforce Developer Console becomes an invaluable tool. Whether you’re troubleshooting an issue or simply monitoring performance, the Developer Console helps you track the activity of your Apex class effectively.

In this blog, we’ll walk you through how to track Apex class activity in the Developer Console, with easy-to-follow steps. By the end, you’ll also learn how to use Apex debug logs to analyze your code and enhance your debugging skills.

Why Use the Developer Console?

The Salesforce Developer Console is an integrated tool that allows you to debug, test, and monitor your Apex Code in real time. It simplifies the debugging process, especially for those who want to learn how to debug Apex code in Salesforce. With features like debug logs, query execution, and execution timeline, it gives you an inside look at what your code is doing.

Step-by-Step Guide: Tracking Apex Class Activity

Here’s a straightforward guide to tracking your Apex class in Developer Console:

Step 1: Open the Developer Console

  • Log in to your Salesforce org. and click on the gear icon, then you will be able to see the ‘Developer Console’ option.
Open the Developer Console
  • From the dropdown menu, select Developer Console. This will open a new window where you can monitor and debug your code.
Open the Developer Console 2

Step 2: Set Up Debug Logs

Debug logs capture detailed execution data, such as code execution paths, database queries, and errors. To enable them:

  • In the Developer Console, click on Debug in the top menu and select Change Log Levels.
Set Up Debug Logs
  • Set the log levels for categories like Apex Code, Database, and System to DEBUG. This ensures that you capture all necessary details.
Set Up Debug Logs 2

Step 3: Execute the Apex Class

To track an Apex class:

  • Click on Debug > Open Execute Anonymous Window.
Execute the Apex Class
  • In the window that appears, type the name of the Apex class method you want to run. For example:
apex MyApexClass.myMethod();
  • Click Execute to run the code.
Execute the Apex Class

Alternatively, if the Apex class is triggered by a user action (e.g., clicking a button in the UI), perform the action to generate logs.

Step 4: View Logs in the Developer Console

  • Go to the Logs tab in the Developer Console.
  • Select the most recent log to see a detailed breakdown of the execution.

Logs will show key details, such as:

View Logs in the Developer Console
  • Method calls: Which methods were executed and in what order?
  • Database queries: SOQL queries and their results.
  • Execution time: How long each operation took.

Step 5: Analyse the Execution Timeline

For a visual representation:

  • Click on the Execution Overview or Execution Timeline tab in the log view.
  • When the logs open, a tab header appears with the following options: This Frame, Executable, Debug Only, and Filter.
  • This shows the order and duration of operations, helping you identify bottlenecks.

Step 6: Filter Logs for Specific Events

Use the filter feature to search for specific actions or keywords in the logs. For example:

  • Search for “SOQL” to review database queries.
  • Look for “EXCEPTION_THROWN” to debug errors.

Tips for Effective Debugging in Developer Console

1. Use Checkpoints

Checkpoints let you inspect the state of your variables during execution. Add checkpoints by selecting Debug > Show my Current Checkpoints in the Developer Console.

2. Utilize Salesforce DX (SFDX)

For more advanced debugging and version control, consider integrating Salesforce DX into your workflow. SFDX tools provide additional functionality for tracking and debugging code.

3. Keep Logs Manageable

Debug logs can grow large quickly. Use filters or lower log levels for categories like Workflow or Validation Rules if you don’t need them.

4. Understand Common Log Outputs

Familiarize yourself with common debug log entries, such as:

  • CALLOUT_REQUEST: Indicates an external API call.
  • LIMIT_USAGE_FOR_NS: Shows governor limits.
Understand Common Log Outputs

In Light of These Facts

Tracking an Apex class in the Developer Console is a must-have skill for any Salesforce developer. By using debug logs and tools like the execution timeline, you can pinpoint errors, optimize performance, and improve your Apex Code. Whether you’re debugging or monitoring routine activity, the Developer Console simplifies the process.

By following the steps outlined in this blog, you can easily track and debug your Apex class activity. Don’t forget to explore tools like Salesforce DX for advanced debugging and collaboration.

Latest Salesforce Insights

Gain Business Analyst Skills
from Industry Veterans

Enroll Today!