This question runs in a pre-configured Salesforce environment - no personal connection required.
Create a method that performs complex DML operations with comprehensive error handling.
Parameters:
accounts(List<Account>): List of Account records to processcontacts(List<Contact>): List of Contact records to process
Returns:
Map<String, Integer>: Map containing success counts for each operation
Requirements:
- Use DML insert operations for both accounts and contacts
- Handle DML exceptions gracefully for each operation
- Return a map with keys: 'accounts_inserted', 'contacts_inserted', 'accounts_failed', 'contacts_failed'
- Handle null inputs by returning appropriate counts
- Use try-catch blocks for each DML operation
Example:
List<Account> accounts = new List<Account>{new Account(Name = 'Test')};
List<Contact> contacts = new List<Contact>{new Contact(FirstName = 'John', LastName = 'Doe')};
Map<String, Integer> result = complexDmlErrorHandling(accounts, contacts);
// Returns: {'accounts_inserted' => 1, 'contacts_inserted' => 1, 'accounts_failed' => 0, 'contacts_failed' => 0}
Apex Code Editor
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
Contest Alert
🏆 #CodeEveryDay Feb 2026
Contest runs February 1 - 28. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.