No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Anonymous Blocks
- Developer Console
- Force.com IDE
- The executeAnonymous SOAP API call:
1ExecuteAnonymousResult executeAnonymous(String code)
You can use anonymous blocks to quickly evaluate Apex on the fly, such as in the Developer Console or the Force.com IDE, or to write code that changes dynamically at runtime. For example, you might write a client Web application that takes input from a user, such as a name and address, and then uses an anonymous block of Apex to insert a contact with that name and address into the database.
- Can include user-defined methods and exceptions.
- User-defined methods cannot include the keyword static.
- You do not have to manually commit any database changes.
- If your Apex trigger completes successfully, any database changes are automatically committed. If your Apex trigger does not complete successfully, any changes made to the database are rolled back.
- Unlike classes and triggers, anonymous blocks execute as the current user and can fail to compile if the code violates the user's object- and field-level permissions.
- Do not have a scope other than local. For example, though it is legal to use the global access modifier, it has no meaning. The scope of the method is limited to the anonymous block.
- When you define a class or interface (a custom type) in an anonymous block, the class or interface is considered virtual by default when the anonymous block executes. This is true even if your custom type wasn’t defined with the virtual modifier. Save your class or interface in Salesforce to avoid this from happening. Note that classes and interfaces defined in an anonymous block aren’t saved in your organization.
Even though a user-defined method can refer to itself or later methods without the need for forward declarations, variables cannot be referenced before their actual declaration. In the following example, the Integer int must be declared while myProcedure1 does not:
1Integer int1 = 0;
2
3void myProcedure1() {
4 myProcedure2();
5}
6
7void myProcedure2() {
8 int1++;
9}
10
11myProcedure1();- Status information for the compile and execute phases of the call, including any errors that occur
- The debug log content, including the output of any calls to the System.debug method (see Understanding the Debug Log)
- The Apex stack trace of any uncaught code execution exceptions, including the class, method, and line number for each call stack element
For more information on executeAnonymous(), see SOAP API and SOAP Headers for Apex. See also Working with Logs in the Developer Console and the Force.com IDE.