PDI · Question #117
What are two use cases for executing Anonymous Apex code? Choose 2 answers
The correct answer is B. To schedule an Apex class to run periodically C. To run a batch Apex class to update all Contacts. Anonymous Apex is a powerful tool for quick, ad-hoc execution of Apex code, commonly used for administrative tasks, testing, and initiating batch processes.
Question
What are two use cases for executing Anonymous Apex code? Choose 2 answers
Options
- ATo delete 15,000 inactive Accounts In a single transaction after a deployment
- BTo schedule an Apex class to run periodically
- CTo run a batch Apex class to update all Contacts
- DTo add unit test code coverage to an org
How the community answered
(17 responses)- A6% (1)
- B88% (15)
- D6% (1)
Why each option
Anonymous Apex is a powerful tool for quick, ad-hoc execution of Apex code, commonly used for administrative tasks, testing, and initiating batch processes.
Deleting 15,000 records in a single transaction directly in Anonymous Apex would exceed governor limits; batch Apex (which can be initiated by Anonymous Apex) is designed for large data volumes.
Anonymous Apex can be used to schedule an Apex class that implements the `Schedulable` interface using `System.schedule()`, allowing it to run periodically.
Anonymous Apex is a common way to execute a batch Apex class, initiating large data processing jobs via `Database.executeBatch()`.
Unit tests are typically written in dedicated Apex test classes and methods, and executing code via Anonymous Apex does not count towards code coverage.
Concept tested: Anonymous Apex use cases
Source: https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_development.meta/salesforce_app_development/apex_execute_anonymous_considerations.htm
Topics
Community Discussion
No community discussion yet for this question.