,

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 is different. You defined your method, but there was nothing in your code to cause the method to actually execute.

3.
5. Add the following line to the end of the Apex code in the source window.

testRepeat();

4.
Execute the code again.

Ah, that’s more like it. The next step is to make this method more flexible by adding the ability to control the number of times the debug method executes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.136.183