One of the benefits of Apex classes is code reuse. Class methods can be called by triggers and other classes. Here’s how we save an example class to our organization.

Screenshot 2025-08-06 at 3.45.29 PM.png

Screenshot 2025-08-06 at 3.45.38 PM.png

Screenshot 2025-08-06 at 3.46.33 PM.png

Call a Method to Send an Email

Let’s invoke the public method. We’ll use anonymous Apex execution to do so. Anonymous Apex allows you to run lines of code on the fly and is a handy way to invoke Apex, especially to test out functionality.

Screenshot 2025-08-06 at 3.50.44 PM.png

After executing this function - we can check debug logs to see that the Apex method did, in fact, execute.

Screenshot 2025-08-06 at 3.51.33 PM.png

Call a Static Method

Static methods are easier to call than instance methods because they don’t need to be called on an instance of the class but are called directly on the class name.

We do this by changing out the first line of our code to:

EmailManager.sendMail('Your email address', 'Trailhead Tutorial', '123 body');