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 process
  • contacts (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 account

How 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 May 2026

Contest runs May 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In