nerdexam
Salesforce

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.

Submitted by yuriko_h· Apr 18, 2026Logic and Process Automation

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)
  • A
    6% (1)
  • B
    88% (15)
  • D
    6% (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.

ATo delete 15,000 inactive Accounts In a single transaction after a deployment

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.

BTo schedule an Apex class to run periodicallyCorrect

Anonymous Apex can be used to schedule an Apex class that implements the `Schedulable` interface using `System.schedule()`, allowing it to run periodically.

CTo run a batch Apex class to update all ContactsCorrect

Anonymous Apex is a common way to execute a batch Apex class, initiating large data processing jobs via `Database.executeBatch()`.

DTo add unit test code coverage to an org

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

#Anonymous Apex#Batch Apex#Scheduled Apex#Apex Execution

Community Discussion

No community discussion yet for this question.

Full PDI Practice