创建列表
跟随 Trail Together 进行学习
进行这一步骤时,想要跟专家一起学习吗?观看此视频,它是 Trail Together 系列的一部分。
(这部分内容从 13:30 开始,如果您想要倒回去再次观看步骤的开头部分可以从这里开始。)
创建并调整列表
将名为 bankAccts 的列表实例化并且给该列表增加两个 BankAcct 对象。
- 打开 Execute Anonymous(执行匿名)窗口。
- 把现有代码替换为这个代码:
//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 savAcct 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 List class, instantiate a BankAcct List object named bankAccts 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);
- 确认 Open Log(打开日志)被选中,然后单击 Execute(执行)。执行日志打开。
- 选中 Debug Only(仅限调试)。
- 查看调试消息,然后关闭日志。
在 createContact 方法中,把一个 Contact List(联系人列表)对象实例化,接受一个称作 candsFromTrigger 的 Candidate List(候选人列表)对象作为参数。
- 在 Developer Console 中,打开 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>(); } }
- 保存 CreateContactFromCan 类。