O'Reilly logo

Learning Apex Programming by Matt Kaufman, Michael Wicherski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required