Skip to content
Dhaval Heruwala edited this page Apr 17, 2020 · 20 revisions

Welcome to the SFLogging wiki!

Install the unlocked package in your Org

Package Installation URL: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t1U0000058XjyQAE

Test the functionality

Once the package is installed, to test the functionality,

  1. Open the Event Logger App and Developer console in the Browser side by side and
  2. paste and execute the following code in Debug > Execute Anonymous Window
Log.push('MyClass.methodA'); 
  insert new Account (name = 'Test'); 
  Log.push('MyClass.methodB'); 
    Log.message('Doing something'); 
    insert new Account (name = 'Test'); 
  Log.pop(); 
  
  List accounts = [select Id from Account]; 
  
  Log.push('MyClass.methodC'); 
    List accounts2 = [select Id from Account]; 
  Log.pop(); 
  Log.message('Doing something else'); 
Log.pop(); 

Database.rollback(sp); 

Log.emit();

Example of embedding logger in your Apex Code

In your developer console, add a Demo Class CustomLogEventDemo.apxc

public class CustomLogEventDemo{
  public static void TestSOQLTolerance(){
    Log.push('MalformedQuery.TestSOQLTolerance');
      Log.message('Testing SOQL Tolerance Logging');
      
      Opportunity[] opps = [SELECT Name,NextStep FROM Opportunity];
      opps = [SELECT Name,Probability,StageName FROM Opportunity];
    Log.pop();

    Log.emit();
  }
}

Test the Logging by pasting CustomLogEventDemo.TestSOQLTolerance(); in Debug > Execute Anonymous Window in the developer console.

Some Commands

Create a Package Version:

sfdx force:package:version:create -p SFLogging -d force-app -x -w 10

sfdx force:source:push -f for forcing

sfdx force:source:pull

Clone this wiki locally