User Permissions Needed | |
---|---|
To execute anonymous Apex: (Anonymous Apex execution through the API allows restricted access without the “Author Apex” permission.) |
“Author Apex” |
ExecuteAnonymousResult 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.
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:
Integer int1 = 0; void myProcedure1() { myProcedure2(); } void myProcedure2() { int1++; } myProcedure1();
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.
To run any Apex code with the executeAnonymous() API call, including Apex methods saved in the organization, users must have the “Author Apex” permission. For users who don’t have the “Author Apex” permission, the API allows restricted execution of anonymous Apex. This exception applies only when users execute anonymous Apex through the API, or through a tool that uses the API, but not in the Developer Console. Such users are allowed to run the following in an anonymous block.
Running any other Apex code isn’t allowed when the user doesn’t have the “Author Apex” permission. For example, calling methods of custom Apex classes that are saved in the organization isn’t allowed nor is using custom classes as arguments to built-in methods.
When users without the “Author Apex” permission run DML statements in an anonymous block, triggers can get fired as a result.