3

I know that the output is not visible, but do the statements actually execute? I have an exception thrown from a beta managed package (json string exceeds heap size limit) and the only time I'm using JSON is in a in a statement like this:

System.debug(JSON.serializePretty(myList));
1

The argument to a System.debug call - in your case a large string created from your list that causes the heap size problem - is evaluated as part of the normal code flow. Internally the System.debug code may just throw it away but it has already been created by that point. (The logging is suppressed in the orgs your managed package is installed in but can be turned on via a support request.)

Other debug API's (e.g. log4j) have methods to allow you to check the enabled level for this very purpose:

if (cat.isDebugEnabled()) {
    cat.debug("This is entry number: " + i );
}

But the Salesforce debug API is missing such methods. So you would have to create your own class and custom setting flags if you really wanted to add such guards. Or more pragmatically, just avoid expensive expressions in debug statements.

  • Yes, that makes perfect sense - fairly obvious now when you think about it. Cheers. – Phil Hawthorn Nov 8 '14 at 12:16

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.