-
Notifications
You must be signed in to change notification settings - Fork 0
/
OlderAccountsUtility.cls
36 lines (34 loc) · 1.24 KB
/
OlderAccountsUtility.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class OlderAccountsUtility {
public static void updateOlderAccounts() {
// Get the 5 oldest accounts
Account[] oldAccounts = [SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5];
// loop through them and update the Description field
for (Account acct : oldAccounts) {
acct.Description = 'Heritage Account';
}
// save the change you made
update oldAccounts;
}
}
/**
* Model Answer
*/
// // Apex classes should declare a sharing model if DML or SOQL is used
// public with sharing class OlderAccountsUtility {
// public static void updateOlderAccounts() {
// // Validate CRUD permission before SOQL/DML operation
// if (!Schema.sObjectType.Account.isAccessible() && !Schema.sObjectType.Account.isUpdateable()) {
// return;
// }
// /**
// * Developers should always use a SOQL for loop to process query results that return many records,
// * to avoid the limit on heap size.
// */
// Account[] oldAccounts = new List<Account>();
// for (Account account : [SELECT Id, Description FROM Account ORDER BY CreatedDate ASC LIMIT 5]) {
// account.Description = 'Heritage Account';
// oldAccounts.add(account);
// }
// update oldAccounts;
// }
// }