Scenario: You are working for a company that manages a large number of customer records. The company wants to update the email addresses of all customers based on certain criteria. However, due to the large volume of customer data, you need to implement a batch process to update the records efficiently.
Assignment:
- Create a custom object called “Customer__c” with the following fields:
- Name (Text)
- Email__c (Email)
- IsActive__c (Checkbox)
- Write a batch Apex class called “EmailUpdateBatch” that implements the
Database.Batchable<sObject>interface. - Implement the
start,execute, andfinishmethods in the “EmailUpdateBatch” class:- In the
startmethod, query for all active customers whose email addresses need to be updated. - In the
executemethod, iterate over the queried customer records, and update their email addresses. - In the
finishmethod, provide a log or summary of the batch execution.
- In the
- Execute the batch process to update the email addresses of the customers.
- Validate that the email addresses have been successfully updated for the appropriate customer records.
Extra Credit (Optional):
- Include batch monitoring and reporting functionality to track the progress of the batch execution.
This assignment will give you hands-on experience in creating and executing batch Apex classes to efficiently process a large number of records. It will also test your ability to write test classes to ensure the functionality of your code.