ApexSensei

All drills

Write Apex: Apex practice drills

Variables, numbers, text, dates, if and switch, loops, Lists, Sets and Maps. Your Apex foundation.

26 drills · Beginner · Free to run

  1. Comments that survive review (Beginner, 5 min)
    Explain why an Account field is set, switch off scratch logs, and keep the useful log running.
  2. Hello, ApexSensei (Beginner, 5 min)
    Run your first Apex statement in Salesforce and read its labeled debug output.
  3. Quick win: double a number (Beginner, 5 min)
    Write a one-line method that returns a number times two. Your first method that returns a value.
  4. Quick win: greet by name (Beginner, 5 min)
    Join text and a variable with + to build a greeting for any name.
  5. Quick win: is it positive? (Beginner, 5 min)
    Return true or false from a comparison. Meet the Boolean type and see what happens with null.
  6. Quick win: make initials (Beginner, 5 min)
    Take the first letter of two names, make them capitals and join them.
  7. Quick win: pick the larger number (Beginner, 5 min)
    Return the bigger of two numbers. Your first if.
  8. Quick win: shout it (Beginner, 5 min)
    Turn text into capitals and add an exclamation mark.
  9. Quick win: join a full name (Beginner, 5 min)
    Put a first and last name together with one space between them.
  10. Quick win: is the name blank? (Beginner, 5 min)
    Use String.isBlank to treat null, empty text and spaces the same way.
  11. Integer division and Math.mod (Beginner, 10 min)
    Count full seat packs with integer division and leftover seats with Math.mod for two order sizes.
  12. Money is a Decimal (Beginner, 10 min)
    Round Opportunity tax and total with HALF_UP, and see how plain setScale(2) rounds a tie differently.
  13. True, false, and null (Beginner, 12 min)
    Give a missing Lead score a default before doing math, then decide if the Lead is hot in three cases.
  14. Clean a Contact name (Beginner, 12 min)
    Trim spaces, fix capital letters, and drop a temporary suffix from imported Contact names.
  15. Parse an email (Beginner, 12 min)
    Split Contact emails at the @ into mailbox and domain, and handle an email with no @ safely.
  16. Split and join text (Beginner, 12 min)
    Split a multi-select picklist value into a List, add a value, join it for display, and split on dots safely.
  17. Working with dates (Beginner, 10 min)
    Build Dates, cross a year end, add a month to Jan 31, and count the days between two dates.
  18. Score bands with else if (Beginner, 12 min)
    Write a method that sorts a Lead score into Hot, Warm, Cold or Unscored with if / else if / else.
  19. Switch on Case status (Beginner, 10 min)
    Pick an action for Case statuses with switch on, a when else default, and a status typed in lowercase.
  20. For loop: number invoices (Beginner, 10 min)
    Number three invoices with a for loop, count the passes, and run the loop again with zero invoices.
  21. For-each over Accounts (Beginner, 12 min)
    Loop over in-memory Accounts with for-each, count them, and handle an empty List and a null List safely.
  22. While a queue has work (Beginner, 12 min)
    Work through an in-memory queue from the front with a while loop until it is empty, and show an empty queue does no work.
  23. Lists of Opportunities (Beginner, 15 min)
    Add, read and change in-memory Opportunities in a List, and read items only at safe positions.
  24. Maps: Id to Account (Beginner, 15 min)
    Build an Id-to-Account Map from a List, look up known and missing keys, and loop over every key.
  25. Remove duplicate emails with a Set (Beginner, 12 min)
    Write a method that counts different emails with a Set<String>, ignoring letter case and skipping empty entries.
  26. Count Leads by Rating with a Map (Beginner, 15 min)
    Write a method that counts Leads per Rating in a Map<String, Integer>, then loop over its keys to print each count.

Start practicing free