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.
[References:Anonymous Apex:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_execute_anonymous.htm, , ]
Submit