Skip to main content

リスト FOR ループの作成

メモ

メモ

日本語で受講されている方へ
このバッジの Trailhead ハンズオン Challenge は英語で受講していただく必要があります。英語の意味についてはかっこ内の翻訳をご参照ください。必ず英語の値をコピーして貼り付けてから、Trailhead Playground の言語を [English] に、ロケールを [United States] に切り替えてください。こちらの指示に従ってください。

翻訳版の Trailhead を活用する方法については、自分の言語の Trailhead バッジをご覧ください。

Trail Together の動画

エキスパートの説明を見ながらこのステップを進めて行きたい場合は、Trail Together シリーズの一部である、こちらの動画をご覧ください。

(巻き戻して最初から見直したい場合、このクリップは 17:24 分から開始されます。)

ループを調整する

リスト FOR ループを追加して、作成した bankAccts リストを反復処理します。 

  1. 開発者コンソールで、[Execute Anonymous (匿名実行)] ウィンドウを開きます。
  2. 既存のコードを次のコードに置き換えます。
    //From the BankAcct class, instantiate an object named chkAcct
    BankAcct chkAcct = new BankAcct();
    //Set the accttype attribute of the chkAcct object to Checking
    chkAcct.accttype = 'Checking';
    //Set the acctName attribute of the chkAcct object to D.Castillo-Chk
    chkAcct.acctName = 'D.Castillo-Chk ';
    //Invoke the makeDeposit method with 150 as the argument
    chkAcct.makeDeposit(150);
    //From the BankAcct class, instantiate an object named bankAccts
    BankAcct savAcct = new BankAcct();
    //Set the accttype attribute of the savAcct object to Savings
    savAcct.accttype = 'Savings';
    //Set the acctName attribute of the savAcct object to D.Castillo-Sav
    savAcct.acctName = 'D.Castillo–Sav';
    //Invoke the makeDeposit method with 220 as the argument
    savAcct.makeDeposit(220);
    //From the BankAcct class, instantiate an object named savAcct
    List<BankAcct> bankAccts = new List<BankAcct>();
    System.debug('The BankAcct List has ' + bankAccts.size() + ' bank accounts.');
    //Add the chkAcct object to the bankAccts list
    bankAccts.add(chkAcct);
    //Add the savAcct object to the bankAccts list
    bankAccts.add(savAcct);
    System.debug('The BankAcct List has ' + bankAccts.size() + ' bank accounts.');
    System.debug('Here is the list: ' + bankAccts);
    //Declare a list FOR loop that uses an iteration variable named tempacct
    //to loop through the bankAccts list
    for (BankAcct tempacct:bankAccts){
        system.debug(tempacct.acctName + ' is a ' + tempacct.accttype +
        ' account with a balance of $'+ tempacct.getBalance());
    }
  3. [Open Log (ログを開く)] が選択されていることを確認してから、[Execute (実行)] をクリックします。実行ログが開きます。
  4. [Debug Only (デバッグのみ)] を選択します。
  5. デバッグメッセージを確認し、ログを閉じます。

createContact メソッドで、リスト FOR ループを追加して、Candidate (応募者) リストを反復処理します。

  1. CreateContactFromCan クラスで、既存のコードを次のコードに置き換えます。
    public with sharing class CreateContactFromCan {
        //Declare a method that returns void and accepts a Candidate list named candsFromTrigger
        public void createContact (List<Candidate__c> candsFromTrigger){
            //Instantiate a Contact list named conList
            List<Contact> conList = new List<Contact>();
            //Declare a list FOR loop that uses an iteration variable named currentCandidate
            //to loop through the candsFromTrigger list
            for(Candidate__c currentCandidate:candsFromTrigger){
            }
        }
    }
  2. CreateContactFromCan クラスを保存します。
無料で学習を続けましょう!
続けるにはアカウントにサインアップしてください。
サインアップすると次のような機能が利用できるようになります。
  • 各自のキャリア目標に合わせてパーソナライズされたおすすめが表示される
  • ハンズオン Challenge やテストでスキルを練習できる
  • 進捗状況を追跡して上司と共有できる
  • メンターやキャリアチャンスと繋がることができる