Salesforce Trace Log Query Using Apex


To activate debug logging for users, Apex classes, and Apex triggers, configure trace flags and debug levels in the Developer Console or in Setup. Each trace flag includes a debug level, start time, end time, and log type. The trace flag’s log type specifies the entity you’re tracing.

You can navigate to Setup->Debug then you will see the below screen for trace logs configured in your instance.








If you want to query Trace Log for your instance using Apex then you can use following SOQL query for the same. But please check API Tooling checkbox in developer console while querying.

1. To Query all trace log

SELECT Id, CreatedDate, CreatedById, ExpirationDate, LogType,TracedEntityId,TracedEntity.Name, ApexCode, ApexProfiling,
Callout, Database, System, Validation, Visualforce, Workflow FROM TraceFlag

2. To Query trace log only for class

SELECT Id, CreatedDate, CreatedById, ExpirationDate, LogType,TracedEntityId,TracedEntity.Name, ApexCode, ApexProfiling,
Callout, Database, System, Validation, Visualforce, Workflow FROM TraceFlag where LogType='CLASS_TRACING'

3. To Query trace log only for Developer console

SELECT Id, CreatedDate, CreatedById, ExpirationDate, LogType,TracedEntityId,TracedEntity.Name, ApexCode, ApexProfiling,
Callout, Database, System, Validation, Visualforce, Workflow FROM TraceFlag where LogType='DEVELOPER_LOG'

4. To Query trace log only for USER

SELECT Id, CreatedDate, CreatedById, ExpirationDate, LogType,TracedEntityId,TracedEntity.Name, ApexCode, ApexProfiling,
Callout, Database, System, Validation, Visualforce, Workflow FROM TraceFlag where LogType='USER_DEBUG'

For other Fields, you can refer below salesforce URL.
https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_traceflag.htm

Comments

Popular posts from this blog

System.AsyncException: The Apex job named is already scheduled for execution.

Custom Setting Creation in Apex Test Class

Error : "Trigger must be associated with a job detail"

AJAX Toolkit Debug Shell

how to get object name from id / prefix value in salesforce

How to Query All the batch classes in your Salesforce Instance using APEX

Creating Salesforce Developer Account

Creating MAP from SOQL Query

Custom Pagination Without Controller (Apex)