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
Tom DJTom DJ 

compile error on Exception.getStackTraceString()


I am trying to print the stack trace when an exception occurs using the 
Exception.getStackTraceString() method.    I have cut and paste it from documentation.


I get a compile error that says "Save error: Method does not exist or incorrect signature: [Exception].getStackTraceString()".


I do not get the compile error when I use Exception.getCause() which is another method from the same documentation.


Here is the code simplified.



    // some working code
  } catch (Exception e) {  
            System.debug('MyController() stackTrace: ' + e.getStackTraceString());




Does anyone know if the Exception.getStackTraceString() method is available or if it may be spelled differently?   For some reason, the IDE's method completion feature gives me an error so I can't see what the options are (aggravating!).




Tom DJ.


Cory CowgillCory Cowgill

I think this a misprint in the documentation. Its not available as of Winter 11, not sure about Sprint 11.


This is not a valid method (I have gotten the same error message in my IDE) so they should update the documentation I agree, it is frustrating.


I usually can get the information I need by using the e.getCause() and .getMessage() methods to display/investiage the error.



Tom DJTom DJ

Thanks for the quick response, Cory.


This puts me in somewhat of a dilemna.


I am working on an App Exchange app.   It currently puts out an email to our company support email address when an exception occurs.   It includes tidbits of pertinent debug.   However, we are finding that exceptions that are caught by our top level exception handler (when the exception is not caught locally in a method)  really need a stack trace in order to isolate the cause.  


I believe if the exception is never caught, that salesforce sends out an email with the stack trace, but if we take that approach, we won't be able to capture any other debug.    I have a wrapper class around the debug that could cache all of our debug and would help to close in on a bug, but we are worried about the heap size limits.


Boy would it be nice if the getStackTraceString() method was available.  I guess I should post it on the "Ideas" board.



Tom DJ


Cory CowgillCory Cowgill

Yeah I can understand how that would be frustrating.


Since its in the documentation, it makes you think maybe they removed it for some reason and forgot to update the documentation.


Maybe someone else knows a way around this, but from my experience I haven't been able to get that method to work either. :(


If someone does know a solution please post as I know we aren't the only ones who would like an answer!

Tom DJTom DJ


I just thought of a possible workaround, but I don't have time to implement and  test it until later this afternoon, maybe the weekend.


Here is what I plan to do.


In our top level exception handling code for uncaught exceptions, instead of sending out an email.  I am going to format the debug that we want to send, rethrow a new exception type that I will create, passing in the debug text to the new exception.   This exception will not be caught by the application, but instead will be sent out by salesforce with a stack trace and hopefully the debug.


The only flaw in the plan is that the salesforce email may go to the email address of the customer's sysadmin instead of the email associated with our application.   I am not sure if we want that.  But, if that is where you want it sent, that it is a possible solution for you.


I will let you know as soon as I test my theory.