O'Reilly logo

The Developer’s Guide to the Force.com Platform by Phil Choi, Andrew Fawcett, Glen Martin, Rick Greenwald

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

Creating a Method

Now that you have started to accomplish slightly more complex tasks with your interactive Apex code, you can move on to defining a method in the source window.

Creating a method in the Execute Anonymous window is not something you necessarily do normally, but going through the exercise helps you to get immediate feedback on the syntax and operation of your code.

1.
Change the code in the source window to the following:
public void testRepeat() {
       for (Integer I = 0; I < 5; I++){
    system.debug('Execution ' + I);
 }
}
The method does not return a value, as indicated by the void keyword.
2.
Execute the code. All of a sudden, you are back to the same message you received on your first Apex coding attempt. But the reason this time ...

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