Tuesday 14 May 2013



Execute Anonymous View

The Execute Anonymous view provides an interactive, immediate way to execute arbitrary
blocks of Apex code. Unless noted otherwise, you can execute all the code snippets
in this chapter directly from the Force.com IDE using the Execute Anonymous view.
To try the Execute Anonymous view, first create a new Force.com Project. Go to the
File menu and select File ? New Force.com Project. Enter a project name; enter your
Force.com username, password, and security token; and click the Next button. If you
receive an error on this step, double-check your username, password, and security token.
Also make sure you’re providing the credentials for a Developer Edition organization,
given that other types of organizations might not have access to the Force.com API. Click
the Finish button to create the project.
After you’ve created a project for your Development Edition organization, the Execute
Anonymous view should be visible in the lower-right half of the screen. If not, go to the
Window menu and select Show View --> Execute Anonymous. In the Source to Execute
text box, enter the code given in Listing 5-1. If the text box is not visible, resize your Execute
Anonymous view until it’s tall enough to see it.After you’ve entered the code, click
the Execute Anonymous button to run it.
Listing 5-1 Hello World
String helloWorld(String name) {
return 'Hello, ' + name;
}
System.debug(helloWorld('Apex'));
This sample code defines a function called helloWorld that accepts a single String
parameter. It then invokes it with the name Apex and displays the results, Hello Apex, to
the debug log

No comments:

Post a Comment