Skip to main content

BankAcct および CreateContactFromCan クラスの作成

メモ

メモ

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

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

Trail Together の動画

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

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

Apex クラスを作成する

BankAcct という名前の Apex クラスを作成します。BankAcct クラスに、balance、acctName、acctType という 3 つの属性を指定します。口座残高を設定するために makeDeposit という名前のメソッドを含めます。

  1. 開発者コンソールで、[File (ファイル)] | [New (新規)] | [Apex Class (Apex クラス)] をクリックします。
  2. [New Apex Class (新規 Apex クラス)] ウィンドウで、BankAcctと入力し、[OK]をクリックします。
  3. [Enter Apex Code (Apex コードを入力)] ウィンドウのコードを次のコードに置き換えます。
    public class BankAcct {
        private integer balance=0;
        public string acctName;
        //Declare a public string attribute named accttype
        public string accttype;
        //Declare a method, named makeDeposit, that accepts an integer named deposit
        //Within the method, add the deposit amount to the balance
        public void makeDeposit (integer deposit) {
        balance = balance + deposit;
        }
        //Declare a method, named getBalance, that returns an integer
        public integer getBalance() {
        //Return the balance attribute
        return balance;
        }
    }
  4. [File (ファイル)] | [Save (保存)] をクリックします。

CreateContactFromCan というクラスと createContact というメソッドを作成します。

  1. [File (ファイル)] | [New (新規)] | [Apex Class (Apex クラス)] をクリックします。
  2. [New Apex class (新規 Apex クラス) ウィンドウで、CreateContactFromCanと入力し、[OK]をクリックします。
  3. [Enter Apex Code (Apex コードを入力)] ウィンドウのコードを次のコードに置き換えます。
    public with sharing class CreateContactFromCan {
        public void createContact(){
        }
    }
  4. CreateContactFromCan クラスを保存します。
無料で学習を続けましょう!
続けるにはアカウントにサインアップしてください。
サインアップすると次のような機能が利用できるようになります。
  • 各自のキャリア目標に合わせてパーソナライズされたおすすめが表示される
  • ハンズオン Challenge やテストでスキルを練習できる
  • 進捗状況を追跡して上司と共有できる
  • メンターやキャリアチャンスと繋がることができる