Apex Tasks

Apex Tasks

This repository contains sample Apex tasks that you can complete in Code Builder or VS Code using the Salesforce Extensions. We constantly add to this list, so make sure you visit this topic often.

Use Anonymous Apex to Mass Update Account Ratings

Say you have accounts with Rating set to Cold because of unfavorable business conditions. You now want to make mass updates to these accounts and change their rating to Warm. You want to limit this update to mid-sized accounts with more than a certain amount of revenue.

This Anonymous Apex code updates ratings of accounts that have an annual revenue greater than $10,000,000 and have more than 1000 employees:

  1. In the scripts/apex folder, create an Anonymous Apex file using the .apex file extension. Paste this code into the file:

       List<Account> acctList =[SELECT Name, Rating FROM Account
         WHERE AnnualRevenue > 500000 AND NumberOfEmployees > 100];
       for (Account acc: acctList){
           if (acc.Rating == 'Cold') {
               acc.Rating = 'Warm'; 
               update acc;
               System.debug(acc.Name + acc.Rating);
  2. Click Execute Anonymous Apex to execute your code.

The DEBUG CONSOLE lists accounts and their updated ratings.


Feedback or Bugs | Edit this Article