Create a BankAcct and CreateContactFromCan Class
Follow Along with Trail Together
Want to follow along with an expert as you work through this step? Take a look at this video, part of the Trail Together series.
(This clip starts at the 8:08 minute mark, in case you want to rewind and watch the beginning of the step again.)
Create Apex Classes
Create an Apex class named BankAcct. Give the BankAcct class three attributes: balance, acctName, and acctType. Include a method named makeDeposit to set the account balance.
- In the Developer Console, click File | New | Apex Class.
- In the New Apex Class window, enter
BankAcct
and then click OK. - Replace the code in the Enter Apex Code window with this code:
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; } }
- Click File | Save.
Create a class named CreateContactFromCan and a method named createContact.
- Click File | New | Apex Class.
- In the New Apex class window, type
CreateContactFromCan
and then click OK. - Replace the code in the Enter Apex Code window with this code:
public with sharing class CreateContactFromCan { public void createContact(){ } }
- Save the CreateContactFromCan class.