Debugging In Salesforce - Part I


If you are ready to accept that your code can run into error, then debug logs can help you to find out the victim. Debug logs give all required information of a transaction to find out what is exactly happening when you perform any kind of action in Salesforce which includes database operation, system processes.You can set debug logs for users, classes and triggers.

Before moving ahead with how to capture debug logs, let’s understand few related terms which we will use while setting debug logs : 

When monitoring debug logs you can specify what you want track or capture in that file. For this Log Category and Log Level helps.

  • Log Category :  With this you can mention what type of information you want to be logged, such as whether you want to get information about Apex or DML operations etc. 
          Below are the different log categories –
       
Category Description
Database This gives information about database operations performed during transaction, including every data manipulation language (DML) statement or inline SOQL or SOSL query.
Apex Code Includes information about Apex code. Can include information such as log messages generated by DML statements, inline SOQL or SOSL queries, the start and completion of
System Includes information about calls to all system methods such as the System.debug method.
Workflow Includes information for workflow rules, flows, and processes, such as the rule name and the actions taken.
Visualforce Includes information about Visualforce events, including serialization and deserialization of the view state or the evaluation of a formula field in a Visualforce page.
Apex Profiling Includes cumulative profiling information, such as the limits for your namespace and the number of emails sent, number of SOQL count, number of records retrieved in whole transaction.
Validation Includes information about validation rules, such as the name of the rule and whether the rule evaluated true or false.
Callout Includes the request-response XML that the server is sending and receiving from an external web service. Useful when debugging issues related to using Lightning Platform web service API calls or troubleshooting user access to external objects via Salesforce Connect.
NBA Includes information about Einstein Next Best Action activity, including strategy execution details from Strategy Builder.


Again, to control how much information to be logged, debug levels come into the picture. With Log Levels  you can set any one of the level for each category. From NONE to FINEST, each level has some defined events that can be logged. You can set these levels as per your need for debugging.
  1. NONE
  2. ERROR
  3. WARN
  4. INFO
  5. DEBUG
  6. FINE
  7. FINER
  8. FINEST

You can check what each level can track for each category by just selecting in debug levels.




And if you are selecting FINE level then all events of ERROR,WARN,INFO and DEBUG will also be tracked.

Let’s go ahead and dive into actual thing. To start capturing logs follow below steps:
  1.  Go to Setup, and enter Debug logs in Quick Find
  2. Click on New in User Trace Flags.
    Trace flag are used to filter the log file. You can specify here debug level, start time, end time, and log type. The trace flag’s log type specifies the entity you’re tracing.
    You can select existing Debug level if already created from Setup > Debug levels or you can create new level here by clicking New Debug Level.

  3. Click on save after filling required information. You’ll land on below screen
  4.  Now perform any operation, and you will find log file generated here on refresh.
  5. Click on View to see the file.

 We'll see how to read this file in next part !!







    Comments

    Popular posts from this blog

    Salesforce Flow - Create multiple records from user input

    Scan barcodes from Salesforce Mobile App

    Zip or Unzip Files in Salesforce