Using the Limits class
If you review a debug log generated by Salesforce when a process runs, you will see at the end of the log a long list of information that details the resource usage for the different namespaces that were invoked during the transaction. An example of this information is shown in the following screenshot:
Figure 19.3 – Resource usage information at the end of a debug log
This information profiles the resource usage for the transaction overall and allows us to see how our resources are being used. While this information is helpful from a transaction-level perspective, for us to profile and analyze which areas of our Apex code need improvement, we need to be able to retrieve similar statistics at multiple steps throughout the transaction.
To retrieve this data, we will need to use the Limits
system class. The Limits
class provides a series of methods in one of two formats: getResourceName
, which returns the current usage of...