---
title: "Current class name"
url: "https://blog.beyondthecloud.dev/tips/current-class-name"
category: "Apex"
tags: "debugging"
published: "2024-01-02"
---

# Current class name

To get the names, simply create a new exception and check a stack trace!

### Current class name

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());

```bash
Class.ExampleController.run: line 3, column 1
Class.AccountsController.runTest: line 14, column 1
```

### Now 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('.'); }

```bash
22:27:55.81 (98588124)|USER_DEBUG|[3]|DEBUG|ExampleController
22:27:55.81 (98702496)|USER_DEBUG|[4]|DEBUG|run
```
