【TrailHead】システム管理者のためのオブジェクト指向プログラミング
sObject と DML の使用
public class AccountHandler {
public static void insertAccount(Integer value) {
Integer counter = 1;
List<Account> addAccounts = new List<Account>();
try {
while(counter <= value){
Account acc = new Account();
acc.Name = 'Acme Inc ' + counter;
acc.AccountNumber = 'A000' + counter;
addAccounts.add(acc);
counter = counter + 1;
}
insert addAccounts;
} catch (DmlException e) {
System.debug('A DML exception has occurred: ' +
e.getMessage());
}
}
}