Skip to main content
Join the Agentforce Hackathon on Nov. 18-19 to compete for a $20,000 Grand Prize. Sign up now. Terms apply.

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.
Condividi il tuo feedback su Trailhead dalla Guida di Salesforce.

Conoscere la tua esperienza su Trailhead è importante per noi. Ora puoi accedere al modulo per l'invio di feedback in qualsiasi momento dal sito della Guida di Salesforce.

Scopri di più Continua a condividere il tuo feedback