Skip to content

Getting Started with Application Events

Johannes Fischer edited this page Jul 6, 2023 · 4 revisions

Use Cases

Application Events are the means to track activities in your Salesforce org and get immediate reporting insights. It is meant for tracking the customizations in your org, whether it is Apex, Flow, Lightning Components, or Salesforce Functions (coming soon). Find out what features are getting used and be able to access additional information for each execution context.

Many Orgs contain Custom Objects to track integration requests. Use Application Events to track any outgoing requests and their payloads and track the outcome, success or failure, in another event. This will allow you to audit all requests and quickly identify if any requests failed.

Application Events vs Logging

Both features serve a similar yet different purpose. Application Events are meant to track features in your org from a more business centric point of view. A product owner can learn about the adoption of new features and use the dashboard to identify issues such as integration failures as outlined above. Once the operation's team is alerted, it can use the Application Event to narrow down the Log Events that need to be reviewed to investigate the root cause of the issues. Application Events add another layer of transparency to your Salesforce applications.

Application Events in a Lightning Web Component

Import the log factory using the following import:

import { applicationEventLogger } from 'c/rflibApplicationEventLogger';

Then, use the logger to record log statements.

handleSomeEvent(event) {
    // Both recordId and additiona information can be null. The record ID must be 18 characters max
    applicationEventLogger.logApplicationEvent('someEventName', null /*recordId*/, 'Some optional information');
}

Application Events in Lightning Component

Insert the wrapper component into any Lightning Component, preferably at the top of the markup.

<c:rflibApplicationEventLogger aura:id="applicationEventLogger" />

Then retrieve the Application Event Logger from your controller or helper code.

({
    doInit: function(component, event, helper) {
        var applicationEventLogger = component.find('applicationEventLogger');

        applicationEventLogger.logApplicationEvent('someEventName', null /*recordId*/, 'Some optional information');
    }
})

Application Events in Apex

Create a Application Event Logger in your Apex class using the following command:

private static final rflib_ApplicationEventLogger APP_EVENT_LOGGER = rflib_LoggerUtil.getApplicationEventLogger();

Then call the log function.

APP_EVENT_LOGGER.logApplicationEvent('import-sample-data-async', null /* recordId */, null /* addtional details */);

Application Events in Flow Builder

Application Events are also supported in Flow using Apex Actions.

In Flow Builder, add an Action element to your Flow. When the New Action modal appears, select RFLIB as the category on the left and search for the Application Event action in the right column. Once selected, fill out the standard action fields by giving it a unique name and define your log parameters. Please note that there are two optional parameters that can be configured by enabling the toggle at the bottom of the form. The screenshot below illustrates the configuration.

alt text

Application Events in Salesforce Functions

To use Application Events in Salesforce Functions, check out the SF Function Wiki Page.

Clone this wiki locally