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

Get The Developer’s Guide to the Force.com Platform 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.