Class is in session

As we mentioned before, when we write triggers, the majority of code goes into our Apex classes, not the triggers themselves. As only the platform can execute the code in a trigger, any code you put in there is inaccessible to you. This means that if you ever need to reuse the same logic, you'd have to rewrite it in a class. If you're going to have it rewritten anyway, you might as well just start off correctly and put it in a class to begin with.

We can create a new Apex class from the Force.com IDE as follows:

  1. Right-click on your project in the Force.com IDE and navigate to New | Apex Class.

    The Create New Apex Trigger window appears as shown:

  2. Enter the name for your new Apex class. For this example, use accountMethods.
  3. Leave ...

Get Learning Apex Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.