Class Name: UpdateContactPointAddressBatch¶
Last Updated: 2025-10-22 Source Code: UpdateContactPointAddressBatch.cls
API Name: UpdateContactPointAddressBatch Type: Batch Test Coverage: Not specified
Business Purpose¶
This batch class anonymizes ContactPointAddress records for accounts that have been marked as anonymized, supporting GDPR and data privacy compliance. It removes personally identifiable address information while maintaining data structure integrity for system operations.
Class Overview¶
Scope and Sharing¶
- Sharing Model: with sharing
- Access Modifier: public
- Interfaces Implemented: Database.Batchable
, Database.Stateful
Key Responsibilities¶
- Identify ContactPointAddress records linked to anonymized accounts without active users
- Replace address fields with anonymized placeholder data
- Preserve postal code while anonymizing other address components
- Mark processed addresses with Anonymized__c flag
- Process records in batches for efficient large-scale operations
Public Methods¶
start¶
Purpose: Identifies ContactPointAddress records that need anonymization based on parent account anonymization status.
Parameters:
- bc (Database.BatchableContext): Batch context provided by Salesforce
Returns:
- Database.QueryLocator: Query locator for ContactPointAddress records to process, or empty query if no eligible accounts found
Business Logic: - Queries up to 50,000 anonymized accounts - Excludes accounts with active users (PersonContactId NOT IN active User.ContactIds) - Returns ContactPointAddresses where Anonymized__c = false and ParentId in account set - Returns empty query locator if no eligible accounts found
execute¶
Purpose: Anonymizes address data for the batch of ContactPointAddress records.
Parameters:
- bc (Database.BatchableContext): Batch context
- scope (List
Business Logic: - Re-queries related accounts for LastName and PersonMailingPostalCode - Sets Country = null - Sets Name, City, Street = account.LastName (anonymized placeholder) - Sets PostalCode = account.PersonMailingPostalCode - Sets Anonymized__c = true - Updates records with Database.update(allOrNone: false) - Includes debug statements (lines 57, 59)
finish¶
Purpose: Performs cleanup operations after batch completes.
Parameters:
- bc (Database.BatchableContext): Batch context
Business Logic: - Outputs debug message: 'Batch processing completed'
Private/Helper Methods¶
This class contains no private methods.
Dependencies¶
Apex Classes¶
- None
Salesforce Objects¶
ContactPointAddress: Address records being anonymized (City, Street, PostalCode, Country, Name, ParentId, Anonymized__c)Account: Parent accounts (Anonymized__c, LastName, PersonMailingPostalCode, PersonContactId)User: Active users used to filter out accounts (ContactId, isActive)
Custom Settings/Metadata¶
- None
External Services¶
- None
Design Patterns¶
- Batch Pattern: Processes large datasets in manageable chunks
- Stateful Pattern: Implements Database.Stateful (though no state variables are used)
- Query Locator Pattern: Uses two-step query approach (accounts first, then addresses)
Governor Limits Considerations¶
SOQL Queries: 3 queries total (1 in start for accounts, 1 in start for addresses, 1 in execute for account details) DML Operations: 1 DML per batch execution (max 200 records per execute) CPU Time: Low - simple field assignments Heap Size: Moderate - stores account map and address list in memory
Bulkification: Yes - processes up to 200 addresses per execute Async Processing: Yes - runs asynchronously as batch job
Limits: - LIMIT 50000 on accounts query (hardcoded) - Default batch size (200 records per execute) - Database.update with allOrNone: false (partial success allowed)
Error Handling¶
Strategy: - Database.update with allOrNone: false allows partial success - No explicit try-catch blocks - No error logging or notification
Logging: - Debug statements on lines 57 and 59 (should be removed for production) - finish() method logs completion
User Notifications: - None
Missing: - No error handling for SOQL failures - No logging of failed record updates - No notification mechanism for batch failures
Security Considerations¶
Sharing Rules: Enforces sharing (with sharing) - respects OWD Field-Level Security: Not enforced - direct field access CRUD Permissions: Not enforced - assumes batch has update access Input Validation: Minimal - relies on database constraints
Data Privacy: - Anonymizes PII data for GDPR compliance - Irreversible operation - backups critical
Test Class¶
Test Class: UpdateContactPointAddressBatchTest.cls Coverage: Not specified Test Scenarios Needed: - Accounts with anonymized ContactPointAddresses - Accounts without ContactPointAddresses - Active user filtering logic - Large volume testing (50,000+ accounts) - Partial failure scenarios (allOrNone: false) - Empty result set handling
Changes & History¶
- No documented change history available
Pre-Go-Live Concerns¶
CRITICAL - Fix Before Go-Live¶
- DEBUG STATEMENTS: Remove System.debug statements on lines 57, 59 before production
- NO ERROR HANDLING: Missing try-catch and error logging for failed updates
- IRREVERSIBLE OPERATION: No rollback mechanism - ensure backups exist
- ACTIVE USER FILTER LOGIC ISSUE: Line 9 uses "isActive = false" which excludes INACTIVE users (should be "isActive = true")
HIGH - Address Soon After Go-Live¶
- Add comprehensive error handling with try-catch blocks
- Implement logging for failed anonymizations (Custom Object or Platform Events)
- Add email notifications for batch completion/failure
- Implement retry mechanism for failed updates
- Add validation to prevent re-anonymizing already anonymized records
- Consider adding AsyncApexJob monitoring
MEDIUM - Future Enhancement¶
- Make anonymization patterns configurable (Custom Metadata)
- Add audit trail tracking anonymization events
- Implement batch chaining for related objects
- Make LIMIT 50000 configurable
- Add progress tracking and reporting
- Consider using Queueable for smaller volumes
LOW - Monitor¶
- Monitor batch execution time and heap size
- Track number of failed record updates
- Review batch size optimization (default 200 may not be optimal)
- Monitor impact on system performance during batch execution
Maintenance Notes¶
Complexity: Medium Recommended Review Schedule: Quarterly Key Maintainer Notes: - This batch is part of a larger anonymization framework - coordinate changes with related batches - The 50,000 account limit is hardcoded - may need adjustment based on data volumes - Active user filter may need review - current logic on line 9 seems inverted (isActive = false) - Database.update with allOrNone: false means some records may fail silently - Anonymization logic uses LastName and PersonMailingPostalCode from Account - ensure these fields are populated - Country is set to null (line 48) which may break address validation logic - The two-step query (accounts then addresses) is less efficient but necessary due to relationship complexity - Consider scheduling during off-peak hours due to data updates - Backup ContactPointAddress records before running in production - Test impact on address-dependent features (shipping, billing, geocoding)