Skip to main content

创建 BankAcct 和 CreateContactFromCan 类

备注

备注

用中文(简体)学习?在此徽章中,Trailhead 实践挑战验证使用英文。括号中提供了译文,用作参考。确保复制粘贴英文值,将 Trailhead Playground 切换为英语,将区域设置切换为美国。按此处说明进行。

查看 Trailhead 本地化语言徽章了解如何利用 Trailhead 译文。

跟随 Trail Together 进行学习

进行这一步骤时,想要跟专家一起学习吗?观看此视频,它是 Trail Together 系列的一部分。

(这部分内容从 08:08 开始,如果您想要倒回去再次观看步骤的开头部分可以从这里开始。)

创建 Apex 类

创建称作 BankAcct 的 Apex 类赋予 BankAcct 类三个属性:balance、acctName 和 acctType。加入称作 makeDeposit 的方法,用来设置帐户余额。

  1. 在 Developer Console 中,单击 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 类。
继续免费学习!
注册帐户以继续。
有什么适合您的内容?
  • 为您的职业目标获取个性化推荐
  • 通过实践挑战和测验练习您的技能
  • 跟踪并与雇主分享您的进度
  • 与人联系以获取指导和就业机会