3

If I create a TraceFlag with ScopeId = null and TracedEntityId = id of my trigger on contact Object {contactTrigger}--> ApexLogs are not generated each time a contact is created or updated. Note: I made sure that the expirationDate is greater than Now.

If I create a TraceFlag with scopeId = myUserId and TracedEntityId = id of my trigger on contact Object {contactTrigger}--> ApexLogs are not generated each time a contact is created or updated. Note:I made sure that the expirationDate is greater than Now.

I did noticed that ApexLogs are generated when I modify/create a contact, if I have a second TraceFlag with scopeId = myUserId and TracedEntityId = myUserId.

Has anyone had a similar problem? Is there a way to have Apex Logs generated each time the ContactTrigger runs, irrespective of whichever user in the org creates/updates a contact? I do not want to create 100 traceflags for 100 users to monitor what is happening when contactTrigger runs.

1

Extract from the TraceFlag docs:

ScopeId

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.
  • When ScopeId=emptyid the user’s actions are traced to the organization’s debug log at the described level.

TracedEntityId

A reference to the following:

  • Apex class
  • Apex trigger
  • User

I've often used both the ScopeId and the TracedEntityId set to the userId of the current active user.

If you go to the Log Filters tab Apex class or trigger and override the Log Filters a Trace flag will be created. Setting Log Filters

Apex Trigger Trace Flag

Note that when it is created the Expiration Date was the time that it was created.

When the trigger fires, this will manifest itself as PUSH_TRACE_FLAGS and then finish at POP_TRACE_FLAGS. enter image description here

It won't however cause the log to be generated, regardless of the expiration date.

This corresponds to the "Check Log Levels" in the developer console, that will show the trigger specific flag under "Class and Trigger Trace Overrides" without an Expiration column.

You will need an active TraceFlag (expiration in the future), with the TracedEntityId of the user in question.

I don't know of a way to trace all the users in an org without creating a TraceFlag for each of them. Support might have some black tab functionality for this, but it isn't directly accessible to us.

Appears the current documentation doesn't align with how logging actually works, at least with respect to creating system logs for specific Apex classes and triggers.


Purely speculation on my part, but I don't think the logging system would work for the trigger or apex class in isolation. When an execution context starts a check is made if logging will be required for the duration based on the user. This same check isn't made for every trigger and class that is called. It wouldn't be practical, as the execution could move in and out of numerous classes and triggers for one execution.

| improve this answer | |
  • The docs say: 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. And it makes sense, coz I used to be able to see logs of other users in the system when I deselect "Show my current logs only" in developer console. Looks like it doesn't work now either. – Shruthi Aug 27 '15 at 6:31
  • Looks like deselecting "Show my current logs only" only shows logs created by users if they had their dev console open/system logs enabled. – Shruthi Aug 27 '15 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.