Apex Tasks

The Apex Recipes Github repository contains sample Apex tasks that you can complete in Agentforce Vibes IDE or VS Code using the Salesforce Extensions.

Use Anonymous Apex to Mass Update Account Ratings 

In addition to the tasks in the Apex Recipes repository, you can complete this sample task to try out running Anonymous Apex in VS Code.

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:

    1```
    2  List<Account> acctList =[SELECT Name, Rating FROM Account
    3    WHERE AnnualRevenue > 500000 AND NumberOfEmployees > 100];
    4  for (Account acc: acctList){
    5      if (acc.Rating == 'Cold') {
    6          acc.Rating = 'Warm';
    7          update acc;
    8      }
    9          System.debug(acc.Name + acc.Rating);
    10  }
    11  ```
  2. Click Execute Anonymous Apex to execute your code.

The DEBUG CONSOLE lists accounts and their updated ratings.

See Also