Newer Version Available

This content describes an older version of this product. View Latest

TraceFlag

Represents a trace flag that triggers an Apex debug log at the specified logging level.

Supported SOAP API Calls

create()delete()describeSObjects()query()retrieve()update()upsert()

Supported REST API HTTP Methods

Query, GET, POST, PATCH, DELETE

Fields

Field Name Details
ApexCode
Type
picklist
Properties
Create, Filter, Group, Restricted picklist, Sort, Update
Description
The log category level for Apex code. Includes information about Apex code and can include information such as log messages generated by data manipulation language (DML) statements, inline SOQL or SOSL queries, the start and completion of any triggers, the start and completion of any test method, and so on. The following are valid values.
  • Finest
  • Finer
  • Fine
  • Debug
  • Info
  • Warn
  • Error

This field is required.

ApexProfiling
Type
picklist
Properties
Create, Filter, Group, Restricted picklist, Sort, Update
Description
The log category level for profiling information. Includes cumulative profiling information, such as the limits for your namespace, the number of emails sent, and so on. The following are valid values.
  • Finest
  • Finer
  • Fine
  • Debug
  • Info
  • Warn
  • Error

This field is required.

Callout
Type
picklist
Properties
Create, Filter, Group, Restricted picklist, Sort, Update
Description
The log category level for callouts. Includes the request-response XML that the server is sending and receiving from an external Web service. This is useful when debugging issues related to SOAP API calls. The following are valid values.
  • Finest
  • Finer
  • Fine
  • Debug
  • Info
  • Warn
  • Error

This field is required.

Database
Type
picklist
Properties
Create, Filter, Group, Restricted picklist, Sort, Update
Description
The log category for database activity. Includes information about database activity, including every DML statement or inline SOQL or SOSL query. The following are valid values.
  • Finest
  • Finer
  • Fine
  • Debug
  • Info
  • Warn
  • Error

This field is required.

ExpirationDate
Type
dateTime
Properties
Create, Filter, Sort, Update
Description
The date and time that the trace flag expires. This field is required.
ScopeId
Type
reference
Properties
Create, Filter, Group, Nillable, Sort, Update
Description
A reference to a user. This field is used with the TracedEntityID field.
  • When ScopeId=user the actions of the user/entity specified by TracedEntityID (user, Apex class or Apex trigger) are traced to the system log at the described level. System logs are visible only to you. Use this scope for class-level filtering. If there are both user and entity-level flags, the user flags take precedence until a method from a class with an entity trace flag is entered. When the method returns, the user trace flags are restored.
  • When ScopeId=emptyid the user’s actions are traced to the organization’s debug log at the described level. Debug logs are visible to all administrators. This option is only available if TracedEntityID references a user (not an Apex class or Apex trigger). The variable emptyid can be the value 0000000000000000 or null.

The scope defined here is reflected in the ApexLog Location field.

System
Type
picklist
Properties
Create, Filter, Group, Restricted picklist, Sort, Update
Description
The log category level for calls to all system methods, such as the System.debug method. The following are valid values.
  • Finest
  • Finer
  • Fine
  • Debug
  • Info
  • Warn
  • Error

This field is required.

TracedEntityId
Type
reference
Properties
Create, Filter, Group, Sort, Update
Description
A reference to the following:
  • Apex class
  • Apex trigger
  • User

This field is used with the ScopeId field. This field is required.

Validation
Type
picklist
Properties
Create, Filter, Group, Restricted picklist, Sort, Update
Description
The log category level for validation rules. Includes information about validation rules, such as the name of the rule, whether the rule evaluated true or false, and so on. The following are valid values.
  • Finest
  • Finer
  • Fine
  • Debug
  • Info
  • Warn
  • Error

This field is required.

Visualforce
Type
picklist
Properties
Create, Filter, Group, Restricted picklist, Sort, Update
Description
The log category level for 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. The following are valid values.
  • Finest
  • Finer
  • Fine
  • Debug
  • Info
  • Warn
  • Error

This field is required.

Workflow
Type
picklist
Properties
Create, Filter, Group, Restricted picklist, Sort, Update
Description
The log category level for workflow rules. Includes information for workflow rules, such as the rule name, the actions taken, and so on. This field is required. The following are valid values.
  • Finest
  • Finer
  • Fine
  • Debug
  • Info
  • Warn
  • Error

Usage

To diagnose a functional issue or a performance problem, use the TraceFlag object to set up logging for yourself or for another user. The following options are available:
  • To set up a log for a specific user, set ScopeId to null and TracedEntityId to the ID of the user. This option can only be configured for a user, not an Apex class or Apex trigger.
  • To configure logging levels for system logs (visible only to you), set ScopeId to user and TracedEntityId to the ID of the logged-in user.
  • To set up a system log (visible only to you) for a specific Apex class or trigger, set ScopeId to null and TracedEntityId to the ID of the Apex class or trigger.
The example below creates a new trace flag and attaches it to an end user.
1//create a new TraceFlag object
2   TraceFlag traceFlag = new TraceFlag();
3   traceFlag.ApexCode = "Finest";
4   traceFlag.ApexProfiling = "Finest";
5   traceFlag.Callout = "Info";
6   traceFlag.Database = "Finest";
7   traceFlag.System = "Debug";
8   traceFlag.Validation = "Info";
9   traceFlag.Visualforce = "Info";
10   traceFlag.Workflow = "Info";
11
12   //set an expiration date
13   traceFlag.ExpirationDate = myTimestamp;
14   //set the ID of the user to monitor
15   traceFlag.TracedEntityId = "005A0000000i93O";
16
17   //call the create method
18   TraceFlag[] traceFlags = { traceFlag };
19   SaveResult[] traceResults = sforce.create(traceFlags);
20   for (int i = 0; i < traceResults.Length; i++)
21   {
22      if (traceResults[i].success)
23      {
24         Console.WriteLine("Successfully created trace flag: " +
25         traceResults[i].id);
26      }
27      else
28      {
29         Console.WriteLine("Error: could not create trace flag ");
30         Console.WriteLine("   The error reported was: " +
31         traceResults[i].errors[0].message + "\n");
32      }
33   }