This question runs in a pre-configured Salesforce environment - no personal connection required.

Given a list of Account records with External_Id__c values, perform an upsert operation using the External_Id__c field as the external ID. Return a map with two keys: 'inserted' containing the count of newly inserted records, and 'updated' containing the count of updated records. Handle null or empty lists by returning a map with both counts set to 0.

Examples:

Input: accounts = [Account with External_Id__c='EXT-001', Account with External_Id__c='EXT-002'] Output: {'inserted' => 2, 'updated' => 0} Explanation: Two new accounts inserted, zero updated Input: accounts = [Account with existing External_Id__c='EXT-001'] Output: {'inserted' => 0, 'updated' => 1} Explanation: One existing account updated, zero inserted Input: accounts = null Output: {'inserted' => 0, 'updated' => 0} Explanation: Null input returns map with zero counts
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.