When we hear the word `logging,` we tend to roll our eyes and groan. Why wouldn’t we? The debug logs in Salesforce are tedious to slog through. But they’re a valuable tool for troubleshooting what’s occurring in our organization.
What if I told you there was a way to use logs to answer questions like:
- How many times a day does this Flow run?
- How many times did this user run a Flow?
- Have all my triggers run for this record?
- What are the most run Flows?
- Where are the most errors?
- Are there any errors?
The good news is you can implement logging to answer these questions quickly and for free!
We will focus on Nebula Logger and how it can transform your Salesforce environment into a well-oiled machine. So, buckle up as we embark on a journey to harness the true power of logging in Salesforce.
What Are Logs?
Logs are records of an event occurring and explain the Who, What, When, and Where.
Typically, we see logs in the Developer Console or those lovely Flow Error dumps.
We see logs With off-the-shelf Salesforce when an Apex class or a Flow fails. Or, we can set debug traces to save logs for some time.
A clear view of user behaviors and system performance helps us to identify roadblocks, address adoption hurdles, and provide effective support.
After all, wouldn’t we want to know errors are occurring before our users submit tickets? Or are the errors systemic or just located to an individual?
We can see these trends in our automations when we enable advanced logging. Since we’re saving each log as a custom record in Salesforce, we can access all our core features, such as reporting.
We tell the logger when to log, for example, when a Flow starts or when a formula inside a trigger evaluates to true. This gives us granular control over what we want to report on. Further, we can tell the logger what to log, such as the date, username, automation name, or flow step.
We can build our own custom logger with custom objects and flows or Apex. But, this would take time away from serving our customers and require additional maintenance.
This is where logging frameworks come into play, offering a structured approach to capturing and analyzing crucial data.
Enter logging frameworks; while they don’t quite give you superpowers, they will make you look like a superhero.
Consider these frameworks as trusted allies that guide you towards optimized user onboarding, streamlined support processes, and higher adoption rates.
Benefits of Logging Frameworks:
- User Insights: Logging frameworks like Nebula Logger grant you unparalleled visibility into user engagement and usage patterns. Analyzing the logged data lets you identify which features resonate most with users, understand pain points, and tailor your training programs accordingly. It’s like having a treasure map guiding you toward optimal user experiences.
- Support and Troubleshooting: Support and troubleshooting become a breeze with logging frameworks. These frameworks expedite the resolution process by capturing detailed error messages and exceptions, empowering your support team to swiftly address issues. Nebula Logger, in particular, provides a structured approach to capture and analyze vital data, helping you bid farewell to guesswork and confidently provide efficient, data-driven support.
There are multiple frameworks out there, such as RFLIB or Nebula Logger. The framework sets up most things for us, and we can customize and extend them for our needs. For this post, we’ll talk about Nebula Logger.
What Is Nebula Logger
Nebula Logger is an open-source project initially developed by Jonathan Gillespie at Salesforce.
It extends logging to all Salesforce automations to include both Apex and Flow. We also get logging in Lightning Web Components (LWC). This covers most of what we need logging for.
Nebula Logger can be installed as either a managed or an unmanaged package. Suppose you want to customize Nebula Logger or build your own plugins. In that case, I’d recommend installing it as an unmanaged package. The downside to this is more Apex tests, which means longer deployment times.
Getting Started with Nebula Logger
Now that we’ve gotten you fired up for logging let’s explore how to start with Nebula Logger.
Follow these steps to implement and leverage Nebula Logger within your Salesforce flows:
To begin, head to the Salesforce AppExchange and install the Nebula Logger package in your Salesforce environment. Once installed, you can access logger configurations from `Custom Settings` and access `Logger Settings.`
After installation, navigate to the Nebula Logger settings within Salesforce.
Customize the log levels and categories based on your specific requirements. This lets you choose which events, errors, or user interactions to log, ensuring you capture the data that matters most to your organization.
Add log statements to your critical Apex triggers, Classes, and Flows. It’s up to you, but I typically add statements at the beginning and end of an automation and any time I perform DML or callouts. This allows me to set up performance monitoring on particular actions.
For Apex, we can leverage numerous functions from the `Logger` class, most of which map to our Debug levels such as `Logger.error()`
Integrating Nebula Logger into your flows lets you capture crucial information and gain valuable insights. Here’s how to do it:
Add a Logging Element
Add a `Add Log Entry` Apex Action from the Flow elements palette within your Flow.
This element lets you specify the event type, message, and any additional details you want to log. You can log user inputs, flow variables, or specific step outcomes. Alternatively, you may use the `Add Log Entry for an SObject Record` for more information; the Nebula documentation is a great resource.
Analysis and Optimization
Once you’ve gathered logging data from your Flows, Apex, and LWC using Nebula Logger, it’s time to look at some data.
Nebula Logger offers built-in reporting and visualization capabilities that allow you to explore your logs, identify trends, uncover bottlenecks, and optimize your flows for a seamless user experience. How is this possible? Because the logs are custom objects in Salesforce, we get Reports and Dashboards!
Leverage these insights to rank your top run automations, identify performance bottlenecks, and set up alerts.
Flows and Triggers can be set up on your logs, allowing them to be sent to Slack if a condition is met or send to Datadog or Splunk for monitoring.
We’ve only scratched the surface of Nebula. I’d recommend checking out the docs on GitHub or through this excellent Salesforce Ben article.
Why Logging is Essential
Now that we have covered the implementation of Nebula Logger, let’s explore the reasons why logging is essential for any type of development:
- Error Identification and Debugging: Flows can become complex, and errors may occur during execution. With Nebula Logger, you gain a structured approach to logging errors within your flows, enabling you to quickly track down and resolve problems. Logging lets you capture errors, exceptions, and debug information, making identifying and resolving issues easier.
- Flow Optimization: Logging provides valuable insights into how your flows are used. By analyzing the logged data, you can identify potential bottlenecks, areas of confusion, or inefficiencies within your flows. This information allows you to optimize your flows, streamline user journeys, and enhance the overall user experience.
- User Behavior Analysis: Understanding user behavior is crucial for driving adoption and improving user experiences. By logging user interactions and capturing flow-related data, you can gain insights into how users engage with your flows. This knowledge empowers you to make data-driven decisions, refine your flows, and align them with user expectations.
- Performance Monitoring: Logging allows you to monitor the performance of your flows. By capturing performance metrics, such as execution times or resource consumption, you can identify potential performance bottlenecks and optimize your flows for improved efficiency. With Nebula Logger, you can effortlessly track and analyze these metrics to ensure optimal flow performance.
Logging frameworks, such as Nebula Logger, unlock a world of possibilities for Salesforce Administrators, Developers, and Architects.
Implementing these frameworks gives you invaluable insights into user behaviors, streamlining support processes, and supercharging user adoption rates.
So, embrace the power of logging, implement Nebula Logger, and witness the transformation of your Salesforce environment.
Get ready to see how your automations perform and know exactly what is happening in your organization.
Want to know when we drop another article? Subscribe to our email list and Happy Logging!