Use Anonymous Apex

An anonymous block is Apex code that doesn’t get stored in the metadata, but that can be compiled and executed.

This example uses 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:
  1. Click Execute Anonymous Apex to execute your code.

The DEBUG CONSOLE lists accounts and their updated ratings.