Debugging Agentforce Actions In Experience Cloud Sites
Debugging Apex classes configured as actions in Agentforce, especially when integrated with Experience Cloud sites, can be challenging but is crucial for ensuring smooth customer interactions. When users interact with an Agentforce agent through a customer portal, understanding the flow and pinpointing issues requires a strategic approach to debugging. This article provides a comprehensive guide on how to effectively debug Agentforce actions within an Experience Cloud site context, ensuring you can monitor and resolve any issues that arise.
Before diving into the debugging process, it’s essential to understand how Agentforce integrates with Experience Cloud. Agentforce, a powerful tool for creating intelligent bots and agents, can be embedded into Experience Cloud sites to provide users with self-service support and automated assistance. When a user interacts with the Agentforce agent—typically through a chat interface—their prompts can trigger specific actions defined in your Apex classes. These actions might include retrieving information, creating cases, or guiding the user through troubleshooting steps.
The integration involves several key components:
- Agentforce Agent: The core of the system, configured with specific intents, entities, and actions.
- Apex Actions: Custom Apex classes that define the logic to be executed when certain intents are matched.
- Experience Cloud Site: The customer-facing portal where the Agentforce agent is embedded.
- Chat Interface: The component within the Experience Cloud site that facilitates interaction between the user and the Agentforce agent.
When a user enters a prompt, the Agentforce agent processes it to determine the user’s intent. If the intent matches a configured action, the corresponding Apex class is invoked. Understanding this flow is crucial for effective debugging, as it helps you identify where issues might be occurring.
To effectively debug Agentforce actions, you need to set up debug logs to capture the execution flow and any potential errors. Salesforce provides robust logging capabilities that can be tailored to your specific needs. Here’s a step-by-step guide on how to set up debug logs:
1. Enable Debug Logs
First, you need to enable debug logs in your Salesforce org. Navigate to Setup and use the Quick Find to search for Debug Log. Click on Debug Logs to access the debug log settings. Enabling debug logs is the foundational step for capturing the necessary information to diagnose issues within your Agentforce actions.
2. Create a New Trace Flag
Trace flags specify which users, Apex classes, and namespaces should have their debug information logged. To create a trace flag:
- Click the New button on the Debug Logs page. This will open a new screen where you can define the parameters for your trace flag. Trace flags are crucial for filtering the logs and focusing on the specific actions and users you want to monitor. Properly configured trace flags ensure that you don't get overwhelmed by irrelevant log data.
- Select the user for whom you want to capture logs. In this case, you should select the user associated with the Experience Cloud site’s guest user or a specific test user. Selecting the correct user is critical for capturing the logs generated by the Agentforce interactions within the Experience Cloud site.
- Set the start and end dates for the trace flag. It’s a good practice to set a reasonable timeframe to avoid generating excessive log data. A well-defined timeframe helps in managing the log volume and makes it easier to analyze the logs within a specific period. Limiting the timeframe also ensures that the logs remain relevant to the debugging session.
- Configure the debug level. You can set different logging levels for various categories such as Apex Code, Database, System, and more. For debugging Agentforce actions, focus on Apex Code and System logs. Setting the appropriate debug level ensures that you capture the right amount of detail without being overwhelmed by excessive information. Apex Code logs are particularly important for tracing the execution of your custom Apex classes, while System logs provide insights into the overall system behavior.
3. Configure Debug Levels
Debug levels define the verbosity of the logs. For Apex Code, you typically want to set the level to INFO or DEBUG to capture detailed information about method calls, variable values, and execution flow. For System logs, INFO is usually sufficient to capture important events and errors. Configuring debug levels appropriately is essential for capturing the necessary details while avoiding unnecessary noise in the logs. A balanced approach to debug levels helps in efficiently identifying the root cause of issues.
- Apex Code:
- DEBUG: Captures the most detailed information, including method entry and exit, variable values, and more. This level is ideal for pinpointing specific issues within your Apex code.
- INFO: Captures important events and messages, providing a good overview of the execution flow. This level is suitable for general debugging and monitoring.
- WARN: Captures warning messages, indicating potential issues that might not necessarily cause errors but should be investigated.
- ERROR: Captures error messages, indicating exceptions or other critical issues that prevent the code from executing correctly.
- FATAL: Captures fatal errors that lead to immediate termination of the process.
- System:
- DEBUG: Captures detailed system events, such as database queries, workflow rules, and more. This level can generate a large volume of logs.
- INFO: Captures important system events, providing a good overview of system behavior. This level is generally sufficient for most debugging scenarios.
- WARN: Captures warning messages related to system events, such as slow queries or performance issues.
- ERROR: Captures error messages related to system events, indicating issues that might impact system functionality.
- FATAL: Captures fatal system errors that lead to system-wide issues.
4. Add Apex Class Filters
In the trace flag settings, you can specify which Apex classes to monitor. Add the Apex classes that are configured as actions in your Agentforce agent. This ensures that logs are captured only for the relevant classes, making it easier to analyze the logs. Filtering by Apex class is a critical step in managing log data, especially in environments with many custom classes. By focusing on the specific classes involved in the Agentforce actions, you can significantly reduce the amount of log data you need to sift through.
5. Save the Trace Flag
Once you’ve configured the trace flag, save it. The trace flag will become active immediately, and logs will start being captured based on your settings. Saving the trace flag activates the logging configuration, ensuring that all relevant interactions and processes are captured in the logs. Verifying that the trace flag is active is a good practice to ensure that the logging is indeed in place.
With the debug logs set up, the next step is to simulate user interactions in the Experience Cloud site to generate log data. This involves interacting with the Agentforce agent as a user would, triggering the actions you want to debug. Simulating user interactions ensures that you generate realistic log data that reflects the actual user experience. This step is crucial for identifying issues that might only occur in a live environment.
1. Access the Experience Cloud Site
Log in to your Experience Cloud site as a user. You might use a test user account or the guest user account, depending on your setup. Accessing the site as a user helps in capturing the logs in the context of actual user interactions, providing a more accurate view of the system's behavior.
2. Interact with the Agentforce Agent
Use the chat interface to interact with the Agentforce agent. Enter prompts that you know should trigger specific actions in your Apex classes. Interacting with the agent through various prompts ensures that all relevant actions are executed and logged. This comprehensive approach helps in uncovering a wide range of potential issues.
3. Trigger Actions
Enter prompts that trigger the specific actions you want to debug. For example, if you have an action that creates a case, enter a prompt that should initiate the case creation process. Intentionally triggering specific actions allows you to isolate and debug those actions, making the debugging process more focused and efficient. Documenting the prompts used and the expected outcomes can also help in validating the fixes.
4. Capture Different Scenarios
Try different scenarios and edge cases to ensure that your actions are working correctly under various conditions. This helps you identify potential issues that might not be apparent under normal usage. Testing edge cases and different scenarios is crucial for ensuring the robustness of your Agentforce actions. This proactive approach can prevent unexpected issues from arising in production environments.
Once you’ve generated sufficient log data, the next step is to analyze the debug logs. Salesforce provides a powerful log viewer that allows you to filter and search logs, making it easier to find the information you need. Analyzing debug logs is a critical skill for any Salesforce developer, as it provides deep insights into the system's behavior and helps in pinpointing the root cause of issues.
1. Access the Debug Logs
Navigate to Setup and use the Quick Find to search for Debug Log. Click on Debug Logs to access the list of generated logs. Accessing the debug logs is the first step in the analysis process. From this list, you can select the logs generated during your simulated user interactions.
2. Open the Relevant Log
Find the log file that corresponds to the user interaction you just performed. Logs are typically listed by the user and the time they were generated. Selecting the correct log file ensures that you are analyzing the data relevant to the specific issue you are investigating.
3. Use the Log Viewer
Salesforce’s log viewer provides various filters and search capabilities. You can filter by log level, time, and other criteria to narrow down the results. The log viewer is a powerful tool for navigating and analyzing log data. Familiarizing yourself with its features can significantly speed up the debugging process.
4. Filter by Apex Class
Use the filters to focus on the log entries generated by your Apex classes. This will help you see the execution flow and any errors that occurred within your code. Filtering by Apex class allows you to concentrate on the specific code that is causing issues, making the debugging process more efficient.
5. Search for Keywords
Use the search functionality to look for specific keywords, such as error messages, method names, or variable values. This can help you quickly identify the source of an issue. Keyword searching is an invaluable technique for quickly locating specific events or errors within the logs. Common keywords to search for include