Create a method that attempts to delete all accounts of a specified type using Database.delete with allOrNone=false. This allows partial success - some deletions may fail while others succeed. Return a map with two keys: 'deleted' (count of successful deletions) and 'failed' (count of failed deletions). Track and process any errors encountered during the deletion process.

This challenge teaches proper error handling with DML operations when working with Database methods that allow partial success. Understanding how to track both successful and failed operations is critical for building resilient Apex applications.

Examples:

Input: accountType = 'Prospect', 10 Prospect accounts exist
Output: {'deleted' => 10, 'failed' => 0}
Explanation: All Prospect accounts deleted successfully with no failures

Input: accountType = 'Customer', 5 Customer accounts exist, 2 have child records preventing deletion
Output: {'deleted' => 3, 'failed' => 2}
Explanation: 3 accounts deleted successfully, 2 failed due to dependencies

Input: accountType = 'Partner', no Partner accounts exist
Output: {'deleted' => 0, 'failed' => 0}
Explanation: No accounts found to delete

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

Note

You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.