Current class name
To get the names, simply create a new exception and check a stack trace!
How to find the name of a class or method that is currently running?
To get the names, simply create a new exception and check a stack trace!
HandledException handledException = new HandledException(); System.debug(handledException.getStackTraceString());
Class.ExampleController.run: line 3, column 1
Class.AccountsController.runTest: line 14, column 1Now let's get only names of Class and Method as Strings:
public class ExecutionUtils { public static String getRunningClass() { HandledException handledException = new HandledException(); return handledException.getStackTraceString() .substringAfterLast('Class.') .substringBefore('.'); }
public static String getRunningMethod() { HandledException handledException = new HandledException(); return handledException.getStackTraceString() .substringAfterLast('Class.') .substringBefore(':') .substringAfter('.'); }
22:27:55.81 (98588124)|USER_DEBUG|[3]|DEBUG|ExampleController
22:27:55.81 (98702496)|USER_DEBUG|[4]|DEBUG|run

