This question runs in a pre-configured Salesforce environment - no personal connection required.
Update all Contact emails from an old domain to a new domain while preserving the local part (username before @). Use Database.update with allOrNone=false to handle partial success scenarios. Return a map with two keys: success (count of successful updates) and failed (count of failed updates).
This pattern is critical during company mergers, rebranding initiatives, or email system migrations where you need to bulk update email addresses while tracking which records succeed or fail.
Examples:
Input: oldDomain = 'oldcompany.com', newDomain = 'newcompany.com', contacts have emails ['john@oldcompany.com', 'jane@oldcompany.com']
Output: {'success' => 2, 'failed' => 0}
Explanation: Both contacts updated successfully from oldcompany.com to newcompany.com
Input: oldDomain = 'legacy.com', newDomain = 'modern.com', contacts have emails ['bob@legacy.com', 'alice@other.com', 'charlie@legacy.com']
Output: {'success' => 2, 'failed' => 0}
Explanation: Only contacts with legacy.com domain are updated to modern.com
Input: oldDomain = '', newDomain = 'new.com'
Output: null
Explanation: Empty old domain returns null
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck