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
Post a Comment