Create an Apex Class

Next, let’s create an Apex class to debug. This class removes cold accounts from a list so that you can focus on more promising clients.

Force.com IDE is in a maintenance-only state. We still provide support for the product through our official channels, but updates prior to October 12, 2019 will be only for critical security issues that arise. On October 12, 2019, we will no longer provide support or updates of any kind for Force.com IDE. On that date, we will also begin archiving documentation and removing download links for the product. We recommend that you start migrating to Salesforce Extensions for Visual Studio Code or one of the great tools made by our partners. For more information, see The Future of Salesforce IDEs on the Salesforce Developers Blog.

Warning

  1. Create an Apex class called AccountViewerController.
  2. Replace your class’s default contents with this code.
    1public class AccountViewerController {
    2
    3
    4   public Boolean removeCold { get; set; }
    5   public List<Account> results { get; set; }
    6
    7
    8   public AccountViewerController() {
    9
    10
    11      removeCold = false;
    12
    13
    14      results = [SELECT Id, Name, Owner.Name, Rating, BillingCity, BillingState 
    15         from Account
    16         WHERE BillingCity = 'Suffragette City'
    17         Order By Name ASC];
    18   }
    19
    20
    21   public List<Account> getAccountTable() {
    22
    23
    24      List<Account> accountsToReturn;
    25      accountsToReturn = new List<Account>();
    26      accountsToReturn.addAll(results);
    27
    28
    29      if (removeCold==true) {
    30         removeColdAccounts(accountsToReturn);
    31      }
    32
    33
    34      return accountsToReturn;
    35   }
    36
    37
    38   public void removeColdAccounts(List<Account> listToReduce) {
    39
    40
    41      System.debug('Removing "cold" accounts');
    42      System.debug('   size before: ' + listToReduce.size());
    43
    44
    45      for (Integer i = 0; i < listToReduce.size(); i++) {
    46         Account a = listToReduce.get(i);
    47         if (a.Rating.equalsIgnoreCase('Cold')) {
    48            listToReduce.remove(i);
    49            System.debug('removed cold account: ' + a.Name);
    50         }
    51      }
    52
    53
    54      System.debug('   size after: ' + listToReduce.size());
    55   }
    56
    57
    58   public void noOp() {
    59   }
    60
    61
    62}
  3. Save AccountViewerController.cls.