ApexSensei

All drills

Apex basics: Apex practice drills

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

Beginner · Free to run

  1. Store the company name Beginner · 5 min

    A String holds text.

  2. Count open cases Beginner · 5 min

    An Integer is a whole number.

  3. Build the account label Beginner · 5 min

    The + operator joins text.

  4. Mark a high score Beginner · 5 min

    An if chooses one path.

  5. Return the tier you were given Beginner · 5 min

    return sends a value back to the caller.

  6. Comments that survive review Beginner · 5 min

    Comments explain code without changing what it does.

  7. Turn on the VIP flag Beginner · 5 min

    A Boolean holds only true or false.

  8. Set the monthly price Beginner · 5 min

    A Decimal holds a number with a decimal point, such as a price.

  9. Set the renewal date Beginner · 5 min

    A Date holds a calendar day.

  10. Pick the shipping fee Beginner · 5 min

    else if adds another test after an if.

  11. Put two regions in a list Beginner · 5 min

    A List<String> holds text values in order.

  12. Add up the seats Beginner · 5 min

    A for-each loop runs once for every item in a list: for (Integer seat : seats) { }.

  13. Hello, ApexSensei Beginner · 5 min

    Apex runs on Salesforce servers, so developers inspect values with System.debug().

  14. Quick win: double a number Beginner · 5 min

    A method takes input and gives back a value with return.

  15. Quick win: greet by name Beginner · 5 min

    + joins text together.

  16. Quick win: is it positive? Beginner · 5 min

    A comparison like n > 0 is already a Boolean: it is true or false.

  17. Quick win: make initials Beginner · 5 min

    Text has built-in methods.

  18. Quick win: pick the larger number Beginner · 5 min

    if runs a block only when its test is true.

  19. Quick win: shout it Beginner · 5 min

    toUpperCase() returns a new copy of the text in capital letters.

  20. Quick win: join a full name Beginner · 5 min

    When you join two variables you must add the glue yourself.

  21. Quick win: is the name blank? Beginner · 5 min

    Three things look empty to a user: null, '' and ' '.

  22. Integer division and Math.mod Beginner · 10 min

    Use Integer for whole counts.

  23. Money is a Decimal Beginner · 10 min

    Salesforce currency is a Decimal.

  24. True, false, and null Beginner · 12 min

    An empty number in Apex is null, not 0.

  25. Clean a Contact name Beginner · 12 min

    Apex String methods such as trim and capitalize turn messy imported text into clean names.

  26. Parse an email Beginner · 12 min

    indexOf and substring split an email address into the part before and after the @.

  27. Split and join text Beginner · 12 min

    split returns a List<String> and reads its argument as regex, so a real dot is '\\.'.

  28. Working with dates Beginner · 10 min

    Build a Date with Date.newInstance.

  29. If a Lead is hot Beginner · 12 min

    if / else if / else picks one answer from several, in order.

  30. Switch on Case status Beginner · 10 min

    switch on compares one value with a list of when branches and runs the first match.

  31. For loop: number invoices Beginner · 10 min

    A for loop has three parts: a start, a test, and a step.

  32. For-each over Accounts Beginner · 12 min

    A for-each loop walks every item in a List in order, with no index to manage: for (Account acct : accounts) { ...

  33. While a queue has work Beginner · 12 min

    A while loop repeats as long as its test is true.

  34. Lists of Opportunities Beginner · 15 min

    A List<Opportunity> keeps records in order: add puts one on the end, [i] reads position i starting at 0, and size() counts them.

  35. Maps: Id to Account Beginner · 15 min

    A Map<Id, Account> stores each Account under its Id.

  36. Remove duplicate emails with a Set Beginner · 12 min

    A Set<String> keeps each value only once.

  37. Count Leads by Rating with a Map Beginner · 15 min

    A Map<String, Integer> can keep a running count per key.

  38. Combine conditions with && and || Beginner · 10 min

    && is true only when both sides are true; || is true when either side is.

  39. Safe navigation with ?. Beginner · 12 min

    The ?. operator returns null instead of throwing when the value on its left is null.

  40. break and continue Beginner · 12 min

    continue skips the current loop iteration; break leaves the loop.

  41. Find the compile error Beginner · 10 min

    Apex refuses to run code that will not compile.

  42. Group records in a Map<String, List<Contact>> Beginner · 12 min

    A Map<String, List<Contact>> groups records by a shared field.

  43. Convert text to Integer, safely Beginner · 12 min

    Integer.valueOf(text) returns the number inside text, but throws on null, empty or non-numeric.

Start practicing free