Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.

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.
Comparta sus comentarios de Trailhead en la Ayuda de Salesforce.

Nos encantaría saber más sobre su experiencia con Trailhead. Ahora puede acceder al nuevo formulario de comentarios en cualquier momento en el sitio de Ayuda de Salesforce.

Más información Continuar a Compartir comentarios