Debugging Salesforce Triggers
Last updated
Was this helpful?
Last updated
Was this helpful?
Salesforce Triggers within customer orgs can cause issues with Archive and Restore functionality for a number of reasons. Triggers represent arbitrary code execution in the midst of GRAX interacting with data; their effects can be unpredictable and destabilizing. This document provides guidance on how to debug Triggers that may be causing issues with GRAX.
Debugging of Triggers may become necessary when:
Archive or Restore jobs are failing due to Apex CPU timeouts.
Archive or Restore jobs are failing due to Apex governor limits.
Archive or Restore jobs are failing due to unhandled exceptions in Apex code.
Archive or Restore jobs are failing due to integrity/validation errors on unrelated records/objects.
Trace Flags are the most powerful tool for debugging triggers. They allow you to review the execution of your code after the fact at a low level, and can be used to identify the root cause of issues including where in the Trigger code the problem is occurring. For information on how to set a Trace Flag for a given user, class, or trigger, see the .
Note the following:
Most triggers and automation in Salesforce run in "System Mode" and will not be affected by Trace Flags scoped to the user that triggers the operation. To capture logs for these automated operations, you must set a Trace Flag for the System user. See below for more information.
Class and Trigger flags only override user-scoped flags, if set, and will not enable logging on their own. Enable flagging for the user in question first.
Trace Flags are not retroactive. They must be set before the code is executed to capture the log.
Trace Flags are not permanent. Ensure that your flags have not expired when reproducing issues to avoid missing logs.
To debug operations that run in System Mode, you must set a Trace Flag for the System user. The System user does not show up in the Salesforce GUI in any context, meaning the API must be used to set the Trace Flag. The following steps outline how to set a Trace Flag for the System user:
Use the Salesforce Developer Console to query for the System user ID. The System user's "name" is always 'System': SELECT Id FROM User WHERE Name = 'System'
.
Use the Salesforce Developer Console (in "Tooling API" mode) to query for the Debug Level ID you wish to use: SELECT Id, DeveloperName FROM DebugLevel
. The lowest possible level of logging is recommended.
Use Workbench to set a "USER_DEBUG" trace flag for the System user. Documentation on this process can be found .
GRAX Support cannot directly support the debugging, interpretation, or modification of Customer triggers or automation unrelated to GRAX products. If you require assistance with debugging your triggers beyond the information above, please consult with your Salesforce Administrator and Developer resources, then reach out to Salesforce's Customer Support team for further assistance. If you require assistance related to the GRAX product, please .