function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sf-dev-forum usersf-dev-forum user 

e.getStackTraceString() works for one org and returns null for all others

Hello,

As part of my managed package I'm using the standard Salesforce functionality Exception.getStackTraceString() to get the stacktrace of an exception as a String for better error handling and logging. Unfortunately, this functionality seems to work differently depending on the org the package is installed in, i.e. I get full stacktraces for one org but no stacktraces at all in all other orgs.

There is no documentation in the official docs as to when stacktraces are produced or any possible settings for enabling/disabling stacktraces for managed packages. This feature is critical for being able to quickly fix bugs and any help would be greatly appreciated. 
Yury BondarauYury Bondarau
Hi Mohamed, 

All the logic included to managed package is not displayed in debug log on the org where package installed, except of SOQL queries and DML operations. 
In order to see debug logs on target orgs you need to login as a supporter from your LMA org.

Please check the following thread for more details - https://developer.salesforce.com/forums/?id=906F00000008uUgIAI
sf-dev-forum usersf-dev-forum user
Hello Yury,

Thank you for your suggesstions. Unfortunately, the Salesforce debug logs do not help us with our situation, since we are calling the getStackTraceString() method to forward errors onto our external error handling/logging tool as and when exceptions occur. This enables us to identify errors without having to log into every individual org and check the logs.

I've elaborated on the problem in another post:
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000DDgjIAG

Best,
Julius
Matt Matt 
We're doing something similar and persisting Exception.getStackTraceString to a custom object for review. But the stack trace string shows just empty parentheses ( ) when:

1. the managed code runs asynchronously inside a Batch / Future / Queueable,
2. the catch block encounters any custom exception (solvable by using eg StringException instead)
3. the calling context is using a second class citizen Session ID (eg $Api.Session_ID or GETSESSIONID)

This actually worked some time ago (maybe API 33.0) which was impressive considering all the abstracted smarts that power packaging and background jobs etc. Raised case number 16842403 in hope to recover this very valuable functionality.
Eetay EetayDevEetay EetayDev
please consider upvoting this as feature request: https://success.salesforce.com/ideaView?id=0873A000000PYqWQAW