Skip to main content

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.

  1. In the Developer Console, click File | New | Apex Class.
  2. In the New Apex Class window, enter BankAcct and then click OK.
  3. 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;
        }
    }
  4. Click File | Save.

Create a class named CreateContactFromCan and a method named createContact.

  1. Click File | New | Apex Class.
  2. In the New Apex class window, type CreateContactFromCan and then click OK.
  3. Replace the code in the Enter Apex Code window with this code:
    public with sharing class CreateContactFromCan {
        public void createContact(){
        }
    }
  4. Save the CreateContactFromCan class.
¡Siga aprendiendo gratis!
Regístrese para obtener una cuenta y continuar.
¿Qué hay para usted?
  • Consiga recomendaciones personalizadas para sus objetivos profesionales
  • Practique sus habilidades con retos prácticos y pruebas
  • Siga y comparta su progreso con empleadores
  • Póngase en contacto para recibir asesoramiento y oportunidades laborales