Skip to content

Class Name: UpdateOrderBatch

Last Updated: 2025-10-22 Source Code: UpdateOrderBatch.cls

API Name: UpdateOrderBatch Type: Batch Test Coverage: Not specified

Business Purpose

This batch class anonymizes Order billing and shipping addresses for accounts marked as anonymized, supporting GDPR compliance while maintaining necessary business data for reporting and analytics.

Class Overview

Scope and Sharing

  • Sharing Model: with sharing
  • Access Modifier: public
  • Interfaces Implemented: Database.Batchable, Database.Stateful

Key Responsibilities

  • Identify Order records linked to anonymized accounts
  • Replace billing and shipping address fields with anonymized data
  • Preserve postal code structure
  • Mark processed records with Anonymized__c flag

Public Methods

start

public Database.QueryLocator start(Database.BatchableContext bc)
Purpose: Identifies Orders needing anonymization based on parent account status. Business Logic: Queries up to 50,000 anonymized accounts, excludes accounts with inactive users (NOTE: line 9 has logic issue), returns Orders where Anonymized__c = false

execute

public void execute(Database.BatchableContext bc, List<Order> scope)
Purpose: Anonymizes billing and shipping address data. Business Logic: Sets ShippingCity/Street, BillingCity/Street = account.LastName; ShippingPostalCode, BillingPostalCode = account.PersonMailingPostalCode; Anonymized__c = true

finish

public void finish(Database.BatchableContext bc)
Purpose: Outputs completion debug message.

Dependencies

Salesforce Objects

  • Order: Records being anonymized (ShippingCity, ShippingStreet, ShippingPostalCode, BillingCity, BillingStreet, BillingPostalCode, Anonymized__c)
  • Account: Parent accounts (Anonymized__c, LastName, PersonMailingPostalCode)
  • User: Active user filtering (ContactId, isActive)

Governor Limits Considerations

SOQL Queries: 3 (accounts, orders, account details in execute) DML Operations: 1 per execute batch Bulkification: Yes - processes up to 200 records per execute

Error Handling

Strategy: Database.update(allOrNone: false) allows partial success Logging: Debug statements on lines 58, 60 (remove for production) Missing: No try-catch, no error logging, no notifications

Security Considerations

Sharing Rules: Enforces sharing (with sharing) Field-Level Security: Not enforced CRUD Permissions: Not enforced Data Privacy: Irreversible anonymization - backups critical

Test Class

Test Class: UpdateOrderBatchTest.cls

Pre-Go-Live Concerns

CRITICAL - Fix Before Go-Live

  • LOGIC BUG: Line 9 uses "isActive = false" which filters out INACTIVE users (should be "isActive = true")
  • DEBUG STATEMENTS: Remove System.debug on lines 58, 60
  • NO ERROR HANDLING: Missing try-catch and error logging
  • IRREVERSIBLE: No rollback mechanism - ensure backups exist
  • VARIABLE NAMING: Uses 'cpa' for Order records (confusing)

HIGH - Address Soon After Go-Live

  • Add comprehensive error handling and logging
  • Add email notifications for batch completion/failure
  • Implement retry mechanism for failed updates
  • Review anonymization adequacy with legal team

MEDIUM - Future Enhancement

  • Make anonymization patterns configurable (Custom Metadata)
  • Add audit trail tracking
  • Make LIMIT 50000 configurable

LOW - Monitor

  • Monitor batch execution time
  • Track failed record updates
  • Review variable naming consistency

Maintenance Notes

Complexity: Medium Recommended Review Schedule: Quarterly Key Maintainer Notes: - Part of larger anonymization framework - Active user filter logic on line 9 is inverted (critical bug) - Anonymizes both billing AND shipping addresses - Variable name 'cpa' used for Order records is misleading - Test impact on order reporting and analytics - Backup Order records before running