What are two use cases for executing Anonymous Apex code?
Choose 2 answers
A.
schedule an Apex class to run periodically
B.
To delete 15,000 inactive Accounts in a single transaction after a deployment
C.
To run a batch Apex class to update all Contacts
D.
To add unit test code coverage to an org
The Answer Is:
B, C
This question includes an explanation.
Explanation:
Anonymous Apex allows developers to execute ad hoc code snippets without creating a permanent class or trigger. It is useful for tasks like bulk data manipulation or testing.
B. Deleting 15,000 inactive Accounts:
Anonymous Apex can perform ad hoc bulk operations to clean up data after a deployment.
Example:
Use Cases:List inactiveAccounts = [SELECT Id FROM Account WHERE IsActive__c = false LIMIT 15000];
delete inactiveAccounts;
C. Running a batch Apex class:
Anonymous Apex can execute batch jobs for data processing.
Example:
apex
Copy code
Database.executeBatch(new UpdateContactBatch());
A. Schedule an Apex class to run periodically: This requires a scheduled job, not Anonymous Apex.
D. Add unit test code coverage: Unit tests must be written in test classes and cannot be added using Anonymous Apex.