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

Write a method that updates all Accounts with a specific old industry value to a new industry value. The method should return the count of records successfully updated.

The method should:

  • Accept two parameters: the old industry value to find and the new industry value to set
  • Query for all Accounts with the specified old industry
  • Update those Accounts with the new industry value
  • Use Database.update with allOrNone set to false for error handling
  • Return the count of successfully updated records

Method Signature

public static Integer updateAccountIndustries(String oldIndustry, String newIndustry)

Examples

Example 1:

Input: oldIndustry = "Technology", newIndustry = "Software" Output: 5 Explanation: 5 accounts with Industry "Technology" were updated to "Software"

Example 2:

Input: oldIndustry = "Retail", newIndustry = "E-commerce" Output: 0 Explanation: No accounts with Industry "Retail" were found

Example 3:

Input: oldIndustry = "Manufacturing", newIndustry = "Industrial" Output: 3 Explanation: 3 accounts with Industry "Manufacturing" were updated to "Industrial"
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.